专栏名称: dotNET跨平台
专注于.NET Core的技术传播。在这里你可以谈微软.NET,Mono的跨平台开发技术。在这里可以让你的.NET项目有新的思路,不局限于微软的技术栈,横跨Windows,Linux 主流平台
今天看啥  ›  专栏  ›  dotNET跨平台

如何在不安装 Microsoft Office 的情况下生成 Excel 文件?

dotNET跨平台  · 公众号  ·  · 2021-09-24 08:00
咨询区 mistrmark:我的一个项目中有导出 excel 的功能,但我发现运行代码的机器上一定要安装 Excel,否则就找不到 Microsoft.Office.Interop.Excel ,导致运行报错,请问如何解决?回答区 Mike Webb:你可以在 nuget 上找一下 ExcelLibrary 包,它是免费开源的,参考如下代码://Create the data set and tableDataSet ds = new DataSet("New_DataSet");DataTable dt = new DataTable("New_DataTable");//Set the locale for eachds.Locale = System.Threading.Thread.CurrentThread.CurrentCulture;dt.Locale = System.Threading.Thread.CurrentThread.CurrentCulture;//Open a DB connection (in this example with OleDB)OleDbConnection con = new OleDbConnection(dbConnectionString);con.Open();//Create a query and fill the data table with the data from the DBstring sql = "SELECT Whatever FROM M ………………………………

原文地址:访问原文地址
快照地址: 访问文章快照