如何在c#中创建xls或xlsx文件 [英] How do I create xls or xlsx files in c#

查看:153
本文介绍了如何在c#中创建xls或xlsx文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!



我一直在寻找如何在C#中创建xls文件的示例。我必须使用xls文件以获得下游兼容性。



我所拥有的是每日报告。我想将它们每周/每月合并到一个报告中。

所有文件都有相同的标题和相同类型的数据。



有没有办法轻松组合它们?我可以计算出什么时候和什么时候。



如果有人能让我开始那就太棒了。



我尝试过excellibrary但这似乎不适用于Excel 10.



谢谢!



Nick

解决方案

我不确定你是否真的需要创建XLS及其所有兼容性;这件事太过时了。 XLSX更易于使用,因为您可以使用Open XML SDK。请参阅我过去的回答:

Microsot office Interop [ ^ ]。



按照他们的方式,请阅读微软关于使用Office Interop的文章:

http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2 [ ^ ],

http://support.microsoft.com/kb/257757/en-us [ ^ ]。



无论如何,有一些替代方案。请参阅我过去的答案和其他引用的答案:如何从MS Visual中添加参考添加microsoft excel 15.0对象库Studio 2010 [ ^ ] 。



参见本文,关于Open XML:使用Open XML创建基本的Excel工作簿 [ ^ ]。



-SA

Hi!

I've been searching for an example of how to create a xls file in C#. I have to use xls files for downstream compatibility.

What I have is daily reports pulled. I would like to combine them weekly/monthly into a single report(s).
all the files have the same headers and same type of data.

Is there a way to easily combine them? I can work out the when and whiles.

If someone is able to get me started that would be awesome.

I tried excellibrary but that doesn't seem to work with Excel 10.

Thanks!

Nick

解决方案

I'm not sure you really need to create XLS and all its compatibility; this thing is too outdated. XLSX is easier to work with, because you could use Open XML SDK. Please see my past answer:
Microsot office Interop[^].

By they way, please read Microsoft discouraging articles on using Office Interop:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2[^],
http://support.microsoft.com/kb/257757/en-us[^].

Anyway, there are some alternatives. Please see my past answer and other answers referenced: How to add microsoft excel 15.0 object library from Add Reference in MS Visual Studio 2010[^].

See also this one, on Open XML: Creating basic Excel workbook with Open XML[^].

—SA


这篇关于如何在c#中创建xls或xlsx文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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