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

查看:98
本文介绍了如何直接从.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....

问候,
吉里什

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 上codePLEX下相当的严格的GPL许可,这使得它成为任何人,但实际上爱好者实际上无法使用许可。如果你使用它,你必须揭开它生产的东西,所有的源代码code。

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);
}

完全免费的,可提供源代码,不需要办公室的机器上安装运行(例如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.

马克

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

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