用字符串作为输入在c#中创建简单的excel表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10100901/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
creating simple excel sheet in c# with strings as input
提问by Patan
I am working on creating EXcel sheet in C#.
我正在用 C# 创建 EXcel 表。
No Of columns:4
Name of columns: SNO, Name, ID, Address
There is no constarint on number of rows.
行数没有约束。
SNO Name ID Address
1 A 1122 XXXX
2 B 2211 YYYY
--- --- ---- ---
I have strings as input
我有字符串作为输入
string sno, string name, string Id, string address
I am actually new to C# background.
我实际上是 C# 背景的新手。
Can any one share their view on it like dlls needed etc.
任何人都可以分享他们对它的看法,例如需要的 dll 等。
Thank you
谢谢
采纳答案by Marco
If you include a reference to Excel Interopyou can do whatever you please having Office installed on your system.
如果您包含对Excel Interop的引用,您可以在系统上安装 Office 后做任何您想做的事情。
A little example:
一个小例子:
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();

