c# - 使用字符串作为输入在 C# 中创建简单的 Excel 工作表

标签 c# c#-4.0 datatable

我正在使用 C# 创建 EXcel 工作表。

No Of columns:4
Name of columns: SNO, Name, ID, Address

行数没有限制

         SNO   Name      ID   Address
          1     A         1122  XXXX
          2     B         2211  YYYY


         --- ---        ----    ---

我有字符串作为输入

       string sno, string name, string Id, string address

我实际上是 C# 背景的新手。

任何人都可以分享他们对它的看法,比如需要 dll 等。

谢谢

最佳答案

如果您包含对 Excel Interop 的引用在系统上安装 Office,您可以为所欲为。

一个小例子:

using Excel = Microsoft.Office.Interop.Excel;

Excel.Application excel = new Excel.Application();
excel.Visible = true;
Excel.Workbook wb = excel.Workbooks.Open(excel_filename);
Excel.Worksheet sh = wb.Sheets.Add();
sh.Name = "TestSheet";
sh.Cells[1, "A"].Value2 = "SNO";
sh.Cells[2, "B"].Value2 = "A";
sh.Cells[2, "C"].Value2 = "1122";
wb.Close(true);
excel.Quit();            

关于c# - 使用字符串作为输入在 C# 中创建简单的 Excel 工作表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10100901/

相关文章:

c# - 使用 Owin + OAuth + Google 在 ExternalLogin 上从 HTTP 重定向到 HTTPS

c# - MSBuild:如果给定绝对路径,如何获取文件的相对路径?

c# - "' 表格1 ' already defines a member called ' .ctor ' with the same parameter types "

c#-4.0 - 用于访问文本文件的存储库模式

java - 修复 p :dataTable width in PrimeFaces

c# - 使用 PredicateBuilder 时如何防止对同一个表进行多次连接

c# - 如果断言失败,自定义断言类应该做什么?

c# - 如何在 C# 中使用 HtmlAgilityPack 删除我的 HTML 字符串中的 <br> 标记?

javascript - Django 的 Jquery 数据表插件

.net - DataTable 已属于另一个 DataSet