您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

C#WinForm创建Excel文件的示例代码分享

2024/6/7 5:57:18发布16次查看
下面小编就为大家带来一篇c# winform创建excel文件的实例。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
实例如下:
private bool createxcel(string xlsfile) { try { object missing = system.reflection.missing.value; excel.applicationclass myexcel = new excel.applicationclass(); excel._workbook xbk; //工作薄 excel._worksheet xst; //工作sheet xbk = myexcel.workbooks.add(true); for (int i = 0; i < 1; i++) { xst = (excel._worksheet)xbk.activesheet; xst.name = "sheet" + i; myexcel.sheets.add(missing, missing, 1, excel.xlsheettype.xlworksheet); } //myexcel.visible = true; if (xlsfile.tolower().endswith(".xlsx")) { xbk.saveas(xlsfile, 56, missing, missing, missing, missing, excel.xlsaveasaccessmode.xlshared, missing, missing, missing, missing, missing); } else { xbk.saveas(xlsfile, missing, missing, missing, missing, missing, excel.xlsaveasaccessmode.xlshared, missing, missing, missing, missing, missing); } myexcel.quit(); return true; } catch (exception ex) { messagebox.show("excel创建失败!原因:" + ex.message); return false; } }
以上就是c#winform创建excel文件的示例代码分享的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product