如何直接从.net应用程序创建excel表数据? [英] How to create excel sheet data directly from the .net application?

查看:140
本文介绍了如何直接从.net应用程序创建excel表数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用C#语言从asp.net应用程序创建excel表。

I want to create excel sheet from asp.net application using C# language.

请回复我如何创建它,如果有源。我不知道如何创建它。

please reply me how to create it and also if having source. I don't know how to create it.

另外我想在列之一下拉列表。我们可以这样做。

Also I want drop down list in one of column. how we can do this.

请回复我的紧急....

Please reply me its urgent....

问候,
Girish

Regards, Girish

推荐答案

我正在使用 ExcelPackage 库,它使用Office 2007中的OpenXML标准文件格式,并且很轻松地为您的C#或VB.NET应用程序创建自己的Excel表格,而不用费力。

I'm using the ExcelPackage library which uses the OpenXML standard file format from Office 2007 and makes it really easy to create your own Excel sheets fro your C# or VB.NET app with little effort.

警告词:引起了我的注意(我没有足够重视这个事实), ExcelPackage 实际上是在一个相当严格的GPL许可证下获得许可的,这使得它几乎不可用于除了爱好者之外的任何人。如果你使用它,你将不得不透露你生成的东西的所有源代码。

WORD OF WARNING: it has come to my attention (I didn't pay enough attention to that fact) that the ExcelPackage on CodePlex is actually licensed under a rather strict GPL license, which makes it virtually unusable for anyone but hobbyists. If you use it, you'll have to reveal all your source code of stuff produced with it.

它可能看起来像这样:

using OfficeOpenXml;  // namespace for the ExcelPackage assembly

FileInfo newFile = new FileInfo(@"C:\mynewfile.xlsx"); 
using (ExcelPackage xlPackage = new ExcelPackage(newFile)) 
{
   ExcelWorksheet worksheet = xlPackage.Workbook.Worksheets.Add("Tinned Goods");

   // write some titles into column 1
   worksheet.Cell(1, 1).Value = "Product";

   worksheet.Cell(4, 1).Value = "Peas";
   worksheet.Cell(5, 1).Value = "Total";

   // write some values into column 2
   worksheet.Cell(1, 2).Value = "Tins Sold";

   ExcelCell cell = worksheet.Cell(2, 2);
   cell.Value = "15"; // tins of Beans sold
   string calcStartAddress = cell.CellAddress;  // we want this for the formula
   worksheet.Cell(3, 2).Value = "32";  // tins Carrots sold

   worksheet.Cell(5, 2).Formula = string.Format("SUM({0}:{1})",
   calcStartAddress, calcEndAddress);
}

完全免费,提供源代码,不需要安装Office它运行的机器(例如您的Web服务器),没有缓慢和凌乱的COM互操作 - 它只是像一个魅力!非常推荐。

Totally free, available with source, doesn't require an installation of Office on the machine it runs on (e.g. your web server), no slow and messy COM interop - it just works like a charm! Very highly recommended.

Marc

这篇关于如何直接从.net应用程序创建excel表数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆