需要从ASP.NET任何人创建的二进制Excel文件知道一个好的图书馆? [英] Need a library for creating binary Excel files from ASP.NET anyone know a good one?

查看:100
本文介绍了需要从ASP.NET任何人创建的二进制Excel文件知道一个好的图书馆?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

preferably免费的,如果可能的。

Preferably free if possible.

我已经使用XML / HTML格式的尝试,但我遇到一个问题,即通过Excel提示用户提供一个安全警告,因为内容不符的MIME类型(表下载在网络上),无围绕这样看来

I've tried using xml / html formats but I'm running into a problem where by excel prompts the user with a security warning because the content does not match the MIME type (the sheet is downloaded on the web), no way around this it seems.

推荐答案

[更新]

下载从 codePLEX 的ExcelPackage库。这是围绕一个包装的 System.IO.Packaging程序这是用来创建的Open XML格式文件(DOCX,XLSX,PPTX)。

Download the ExcelPackage library from Codeplex. This is a wrapper around the System.IO.Packaging which is used to create Open XML format files (docx, xlsx, pptx).

添加的样本不包含颜色格式化,但检查该网站上的样品使用的模板,或阅读QA对codePLEX的讨论大约每单元设置多个样式选项。

The added sample does not contain color formating, but check the samples on the site for using a template, or read the discussions on Codeplex for qa's about setting more style options per cell.

public void CreateExcel()
{
    FileInfo newFile = new FileInfo(@"C:\temp\test.xlsx");
    using (ExcelPackage xlPackage = new ExcelPackage(newFile))
    {
        ExcelWorksheet worksheet = xlPackage.Workbook.Worksheets.Add("People");

        // Titles in Column 1
        worksheet.Cell(1, 1).Value = "Name";
        worksheet.Cell(3, 1).Value = "Tom";
        worksheet.Cell(4, 1).Value = "Henry";

        worksheet.Column(1).Width = 20; // set column 1 width                

        // Values in column 2
        worksheet.Cell(1, 2).Value = "Age";
        ExcelCell cell1 = worksheet.Cell(3, 2);                
        cell1.Value = "42"; // Age of Tom
        ExcelCell cell2 = worksheet.Cell(4, 2);
        cell2.Value = "19"; // Age of Henry

        string calcStartAddress = cell1.CellAddress;
        string calcEndAddress = cell2.CellAddress;

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


[原创答案】


[Original answer]

您可以使用ADO.Net。

You can use ADO.Net.

下载<一个href="http://www.microsoft.com/downloads/en/details.aspx?displaylang=en&FamilyID=c06b8369-60dd-4b64-a44b-84b371ede16d"相对=nofollow> Microsoft Access数据库引擎2010可再发行,并检查出的这个帖子如何读/写Excel文件与ADO.Net。

Download Microsoft Access Database Engine 2010 Redistributable and check out this post on how to read/write Excel files with ADO.Net.

只需连接字符串更改为

提供商= Microsoft.ACE.OLEDB.12.0;数据源= pathtoyourfile;扩展属性= Excel的12.0;

使用V12和ACE.OLEDB连接而不是Jet.OLEDB。

Using v12 and the ACE.OLEDB connection instead of Jet.OLEDB.

这篇关于需要从ASP.NET任何人创建的二进制Excel文件知道一个好的图书馆?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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