如何在没有安装excel的开发服务器上,在控制台应用程序中动态创建和写入数据集到excel文件(.xlsx)? [英] How to dynamically create and write dataset to an excel file(.xlsx),in a console application, on a development server with no excel installed?

查看:66
本文介绍了如何在没有安装excel的开发服务器上,在控制台应用程序中动态创建和写入数据集到excel文件(.xlsx)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我已经动态创建了一个.xlsx文件,但是当我打开文件时,它显示文件已损坏或文件格式不受支持。



如何解决这个问题?



注意:所有这一切都需要在使用C#的控制台应用程序中完成。如果您使用Microsoft.Office.Interop.Excel提供解决方案,则更喜欢。



我尝试了什么:



我甚至试过创建一个.xls文件,在本地系统上,但它在excel文件中写入数据后显示一个弹出窗口。所以我必须手动点击保存按钮。如何删除或禁用此功能?

Currently I have created a .xlsx file dynamically but when I am opening the file it shows the file is corrupt or the file format is not supported.

How to solve this issue?

Note: All this needs to be done in Console application using C#.Would prefer if you provide a solution using Microsoft.Office.Interop.Excel.

What I have tried:

I even tried creating a .xls file,on the local system, but it shows a popup after the data gets written in the excel file.So I have to manually click on save button.How can I remove this or disable this?

推荐答案

Google的Open XML SDK。您根本不需要安装Excel。它确实有一个非常陡峭的学习曲线,但它使生活变得如此简单,而无需安装Excel。



如果您的文件已损坏,我想知道是什么你曾经写过这个文件。 .xlsx文件不是单个文件。它实际上是一个包含大量XML文件的ZIP文件。



Google for the "Open XML SDK". You don't need to have Excel installed at all. It does have quite a steep learning curve, but it makes life so much easier without having to have Excel installed.

If your file is corrupt, I'm wondering what you used to write the file. A .xlsx file isn't a single file. It's actually a ZIP file with a bunch of XML files in it.

引用:

如果您使用Microsoft.Office.Interop.Excel提供解决方案,则会更喜欢。

Would prefer if you provide a solution using Microsoft.Office.Interop.Excel.





如果您没有安装Excel,则不可能使用Office Interop。此外,Interop比使用Open XML SDK慢得多。



If you don't have Excel installed, you cannot possibly use Office Interop. Also, Interop is FAR slower than using the Open XML SDK.


这篇关于如何在没有安装excel的开发服务器上,在控制台应用程序中动态创建和写入数据集到excel文件(.xlsx)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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