C# - 转换的xls文件没有Office组件XLSX [英] C# - convert xls file to xlsx without office components

查看:382
本文介绍了C# - 转换的xls文件没有Office组件XLSX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不能安装它的任何办公室的服务器,所以我使用ClosedXML上做Excel文件的一些操作。
,而ClosedXML仅适用于​​.xlsx文件我也有xls文件来处理。
我花了差不多一整天寻找一种方式来转换.xls文件为原来的.xlsx文件,而无需使用任何办公库(因为没有安装在我指定的服务器上...办公室)

I have a server that can't have any office installed on it, so I'm using ClosedXML to do some manipulations on excel files. But ClosedXML only works on .xlsx file and I also have xls file to handle. I spend almost a full day searching for a way to convert .xls files to .xlsx files without using any office libraries (since there is no office installed on my designated server...)

有人可以告诉我怎样才能将这些.xls文件为原来的.xlsx文件?
,因为它需要有安装在服务器上的办公室,我无法使用Microsoft.Office.Interop。

Can someone PLEASE tell me how can I convert these .xls files to .xlsx files ? I can't use Microsoft.Office.Interop because it requires having office installed on the server.

推荐答案

有关 Microsoft.Office.Interop 您需要安装办公。

For Microsoft.Office.Interop you need to have office installed.

您可以使用的 的OleDb 读它(FE成数据表。然后使用像 EPPlus 或的 的OpenXML 写的XLSX文件。 。两者都不需要安装办公室

You could use OleDb to read it(f.e. into a DataTable). Then use a library like EPPlus or OpenXml to write the xlsx file. Both don't need to have office installed.

创建从XLSX文件在数据表与EPPLus很简单:

Creating an xlsx file from a DataTable with EPPLus is easy:

using (ExcelPackage pck = new ExcelPackage(newFile))
{
  ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Name of Worksheet");
  ws.Cells["A1"].LoadFromDataTable(dataTable, true);
  pck.Save();
}



上面的第一个链接显示如何获得数据表从XLS文件。

这篇关于C# - 转换的xls文件没有Office组件XLSX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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