使用.NET中的公式创建Excel工作簿(* .xls)

时间:2023-01-15 11:36:43

I'm working with ASP.NET Webforms and I need to create an report as a Excel file.

我正在使用ASP.NET Webforms,我需要将报告创建为Excel文件。

That should be easy, by changing the ContentType, but I need to dynamically add formulas to some cells.

这应该很容易,通过更改ContentType,但我需要动态添加公式到一些单元格。

Any Ideas?

PS: The format of the excel file should be XLS not XLSX.

PS:excel文件的格式应该是XLS而不是XLSX。

4 个解决方案

#1


I recommend SpreadsheetML for this. It's just an xml schema you can use to create documents that Excel will open as if they were native. You can set formulas, formatting, multiple sheets, and most other excel features.

我建议使用SpreadsheetML。它只是一个xml架构,您可以使用它来创建Excel将打开的文档,就好像它们是本机的一样。您可以设置公式,格式,多个工作表和大多数其他Excel功能。

Be careful when googling for additional info on SpreadSheetML: there's a lot of misinformation out there that confuses SpreadSheetML with the new Xml format used for Excel in Office 2007. It's not. SpreadSheetML works as far back as OfficeXP, and even in a limited sense in Office 2000.

在Google上搜索有关SpreadSheetML的其他信息时要小心:有很多错误信息将SpreadSheetML与Office 2007中用于Excel的新Xml格式混淆。事实并非如此。 SpreadSheetML可以像OfficeXP一样工作,甚至在Office 2000中也是有限的。

If nothing else, the SpreadSheetML link at the beginning of this post also includes a short overview of other options for create Excel files.

如果不出意外,本文开头的SpreadSheetML链接还包括创建Excel文件的其他选项的简短概述。

#2


Have you tried this ExcelXmlWriter library?

你试过这个ExcelXmlWriter库吗?

Also, there is a helper/generator tool that goes with the library.

此外,还有一个与库一起使用的辅助/生成器工具。

It will generate .XLS files. The sample from the website shows:

它将生成.XLS文件。来自网站的样本显示:

using CarlosAg.ExcelXmlWriter;

class TestApp {
    static void Main(string[] args) {
       Workbook book = new Workbook();
       Worksheet sheet = book.Worksheets.Add("Sample");
       WorksheetRow row =  sheet.Table.Rows.Add();
       row.Cells.Add("Hello World");
       book.Save(@"c:\test.xls");
    }
}

#3


I have used Infragistics Excel export/import component for this and it works quite well.

我已经使用了Infragistics Excel导出/导入组件,它运行良好。

It supports formulas and styling and is quite solid. The only downside is that it is quite expensive and must be bought as part of a package.

它支持公式和样式,非常扎实。唯一的缺点是它非常昂贵,必须作为包装的一部分购买。

#4


SpreadsheetGear for .NET will create XLS or XLSX workbooks and includes full formula support.

SpreadsheetGear for .NET将创建XLS或XLSX工作簿,并包含完整的公式支持。

You can see some live ASP.NET Excel Reporting samples here.

您可以在此处查看一些实时ASP.NET Excel报告示例。

Disclaimer: I own SpreadsheetGear LLC.

免责声明:我拥有SpreadsheetGear LLC。

#1


I recommend SpreadsheetML for this. It's just an xml schema you can use to create documents that Excel will open as if they were native. You can set formulas, formatting, multiple sheets, and most other excel features.

我建议使用SpreadsheetML。它只是一个xml架构,您可以使用它来创建Excel将打开的文档,就好像它们是本机的一样。您可以设置公式,格式,多个工作表和大多数其他Excel功能。

Be careful when googling for additional info on SpreadSheetML: there's a lot of misinformation out there that confuses SpreadSheetML with the new Xml format used for Excel in Office 2007. It's not. SpreadSheetML works as far back as OfficeXP, and even in a limited sense in Office 2000.

在Google上搜索有关SpreadSheetML的其他信息时要小心:有很多错误信息将SpreadSheetML与Office 2007中用于Excel的新Xml格式混淆。事实并非如此。 SpreadSheetML可以像OfficeXP一样工作,甚至在Office 2000中也是有限的。

If nothing else, the SpreadSheetML link at the beginning of this post also includes a short overview of other options for create Excel files.

如果不出意外,本文开头的SpreadSheetML链接还包括创建Excel文件的其他选项的简短概述。

#2


Have you tried this ExcelXmlWriter library?

你试过这个ExcelXmlWriter库吗?

Also, there is a helper/generator tool that goes with the library.

此外,还有一个与库一起使用的辅助/生成器工具。

It will generate .XLS files. The sample from the website shows:

它将生成.XLS文件。来自网站的样本显示:

using CarlosAg.ExcelXmlWriter;

class TestApp {
    static void Main(string[] args) {
       Workbook book = new Workbook();
       Worksheet sheet = book.Worksheets.Add("Sample");
       WorksheetRow row =  sheet.Table.Rows.Add();
       row.Cells.Add("Hello World");
       book.Save(@"c:\test.xls");
    }
}

#3


I have used Infragistics Excel export/import component for this and it works quite well.

我已经使用了Infragistics Excel导出/导入组件,它运行良好。

It supports formulas and styling and is quite solid. The only downside is that it is quite expensive and must be bought as part of a package.

它支持公式和样式,非常扎实。唯一的缺点是它非常昂贵,必须作为包装的一部分购买。

#4


SpreadsheetGear for .NET will create XLS or XLSX workbooks and includes full formula support.

SpreadsheetGear for .NET将创建XLS或XLSX工作簿,并包含完整的公式支持。

You can see some live ASP.NET Excel Reporting samples here.

您可以在此处查看一些实时ASP.NET Excel报告示例。

Disclaimer: I own SpreadsheetGear LLC.

免责声明:我拥有SpreadsheetGear LLC。