c# - 如何在文件中写入 C# 中的查询结果。例如(姓名工资)
问题描述
我需要在 .doc 文件中写入 C# 代码中的查询结果
SqlCommand command = new SqlCommand("SELECT Id,Name,Price FROM [Products] WHERE [Id]=@Id ", sqlConnection);
While (await sqlReader.ReadAsync()){
listBox3.Items.Add(Convert.ToString(sqlReader["id"]) + " " +
Convert.ToString(sqlReader["Name"]) + " " + (1 + ((readSearch1 - f) * 1.2) / f));
}
解决方案
您可以使用 Docx 库来执行此操作。 https://cathalscorner.blogspot.com/search?q=create
// Create a new document.
using (DocX document = DocX.Create("Test.docx"))
{
// Create a new Paragraph with the text "Hello World".
Paragraph p = document.InsertParagraph("Hello World.");
// Make this Paragraph flow right to left. Default is left to right.
p.Direction = Direction.RightToLeft;
// Save all changes made to this document.
document.Save();
}
推荐阅读
- google-chrome - Chrome 访问/请求日志
- javascript - 将图片的url转换为base 64
- templates - 如何从 CLI 列出可访问的模板
- react-native - 如何在 react-native 中处理授权码请求?
- vb.net - 在驱动器中搜索包含确切单词的文本文件并进行更改
- python - Django Rest Framework 我不能使用有外键的序列化程序保存模型
- bash - Linux bash脚本:将ls与glob一起使用并在变量中获取输出不起作用
- reactjs - 反应选择组合框可访问性。屏幕阅读器未宣布提供的选项
- django - 合并模型并发送到模板
- android - 在没有应用程序上下文或电话权限的情况下生成唯一的设备 ID