简体   繁体   English

如何在C#中在服务器端创建Excel兼容的电子表格?

[英]How can I create an Excel compatible Spreadsheets on the server side in C#?

I'd like to make server-side excel compatible spreadsheets that maybe use OpenXML or a structured data format. 我想制作可能使用OpenXML或结构化数据格式的服务器端Excel兼容电子表格。

I've used Office Interop before to generate Excel spreadsheets, but those apps run on a PC that has office installed. 我之前使用Office Interop生成Excel电子表格,但这些应用程序在安装了办公室的PC上运行。

For this web project I'm building, the server doesn't have Office installed (and they don't want to buy it). 对于我正在构建的这个Web项目,服务器没有安装Office(并且他们不想购买它)。

What's the best library for me to use that allows me to generate Office compatible spreadsheets from a windows server 2k8 using IIS7? 什么是最好的库供我使用,这允许我使用IIS7从Windows服务器2k8生成Office兼容的电子表格?

Some additional requirements: 一些额外要求:

  • Ideally, free 理想情况下,免费
  • Allows for simple cell formulas that can be inserted at runtime 允许可以在运行时插入的简单单元格公式

try ExcelPackage at codeplex. 在codeplex上试用ExcelPackage its simple and efficient. 它简单而有效。

You can try this library. 你可以试试这个库。

Or the Spreadsheetgear generator. Spreadsheetgear生成器。

Microsoft published the OpenXML SDK . Microsoft发布了OpenXML SDK

Alternatively download the OpenXML schemas, generate simple examples with Office and use them as a foundation to write your own XML files - its not that complicated. 或者下载OpenXML模式,使用Office生成简单示例,并将它们用作编写自己的XML文件的基础 - 它并不复杂。

You could use the NPOI library. 您可以使用NPOI库。

Free, Open source and supports reading and writing Excel, Word and Powerpoint documents 免费,开源并支持读写Excel,Word和Powerpoint文档

A very simple solution is: 一个非常简单的解决方案:

You can build the content of the spreadsheet as a html table. 您可以将电子表格的内容构建为html表格。 Return the table to the browser with the appropriate headers set. 将表格返回到浏览器并设置相应的标题。

Response.ContentType = "application/vnd.ms-excel"

You can even add excel formulas and do simple formatting. 您甚至可以添加excel公式并进行简单格式化。

我们发现SpreadsheetLight既优秀又开源。

看一下Simple OOXML开源库

我已经使用SmartXLS在服务器上创建(和处理)Excel工作表。

You can simply save your data into a comma separated values (CSV) file with .xls extension. 您只需将数据保存为扩展名为.xls的逗号分隔值(CSV)文件即可。

Example: 例:

column1,column2,column3 列1,列2,栏3

value11,value12,value13 value11,value12,value13

value21,value22,value23 value21,value22,value23

value31,value32,value33 value31,VALUE32,value33

value41,value42,value43 value41,value42,value43

value51,value52,value53 value51,value52,value53

Checkout my post Reading Excel Files as a Server Process for a list of some paid ones. 查看我的帖子阅读Excel文件作为服务器进程以获取一些付费的列表。

The one I opted for named FlexCel was very easy to use, allowed formulae to be used at run-time, was fully managed and low cost/royalty free. 我选择名为FlexCel的那个非常容易使用,允许在运行时使用公式,完全管理并且低成本/免版税。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM