使用C#将数据导出到Excel(包括格式化) [英] Export data to Excel (including formatting) using C#

查看:426
本文介绍了使用C#将数据导出到Excel(包括格式化)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序中有一个DataTable,我以前使用CSV文件导出到excel。但是,我想有条件地格式化单元格的背景颜色 - 这显然需要一种新的方法。



问题是这个 - 软件运行的计算机没有Excel。所以我不能下去调用Excel api的路线。



有没有一个简单的方法,我错过了?如果没有,是发布Excel文件的格式还是如何达到这个目标?



谢谢。






编辑:



对于有兴趣的其他人,我最终发现这篇文章,它提供了我发现的最简单的方法。使用Excel 2003。

解决方案

哪个版本的excel?
如果您需要excel 2003,请查看:
http:// www.carlosag.net/Tools/ExcelXmlWriter/



如果你和excel 2007一样,那就是:
http://excelpackage.codeplex.com/ (开源)

http://msdn.microsoft.com/en-us/library/bb448854.aspx (官方MS产品)


I have a DataTable in my program which I have previously exported to excel using a CSV file. However, I want to conditionally format the backgroun colour of cells - which obviously needs a new approach.

The issue is this - the computer where the software will run does not have Excel. So I cannot go down the route of calling the Excel api.

Is there an easy way of doing this that I have missed? If not, is the format of Excel files published or how can I achieve this goal?

Thanks.


EDIT:

For anyone else that is interested, I eventually found this post which provides the simplest method I have found. Works with Excel 2003.

解决方案

Which version of excel? If you need excel 2003, then take a look at : http://www.carlosag.net/Tools/ExcelXmlWriter/

If you're ok with excel 2007, then there's: http://excelpackage.codeplex.com/ (open source) or http://msdn.microsoft.com/en-us/library/bb448854.aspx (official MS product)

这篇关于使用C#将数据导出到Excel(包括格式化)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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