如何以编程方式打开 TSV 文件并将其另存为 XLSX 文件?

发布于 2024-12-24 03:54:21 字数 132 浏览 0 评论 0原文

如果有任何指向我可以使用的文档或 API 调用的指针,我将不胜感激。

基本上,我希望有某种方法可以调用 Excel 进行转换,尽管我还没有找到任何适用于 Excel 2010 的解决方案。

我正在使用 .NET 框架。

I would appreciate any pointers to documentation or API calls I can use.

Basically, I'm hoping there's some way to invoke Excel to make the conversion, although I haven't yet found any solutions that work for Excel 2010.

I am using the .NET framework.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

岛歌少女 2024-12-31 03:54:21

Excel 可以很好地处理 CSV 文件,并且是未自定义 Excel 安装的系统上的默认编辑器。我在几乎所有需要 Excel 文件的情况下都使用 csv 文件,并且与一些非常不懂技术的用户一起工作!

与转换为 xlsx 相比,将 TSV 转换为 CSV 是微不足道的 - 我用于处理平面文件的最佳库之一是 通用解析器 可以读取和写入由任何字符分隔的文件(以及许多其他内容)

Excel handles CSV files well and is the default editor for them on systems where the Excel install hasn't been customised. I use csv files in almost all cases where I need an Excel file and I work with some very non tech-savvy users!

Converting a TSV to a CSV is trivial in comparison to converting to xlsx - one of the best libraries I have used for working with flat files is Generic Parser which can read and write files delimited by any character (amongst many other things)

や三分注定 2024-12-31 03:54:21

我在几个项目中使用 LINQ to CSV 库来加载和操作 CSV、TSV 等文件。

对于创建 Office 文档,如果您想要轻松转换,您就必须付费。它仅真正用于商业应用程序,因此库编写者知道它有市场。

也就是说,有一些免费的库,我听说过这个用于编辑 Excel 文件的好东西:

I have used LINQ to CSV library in several projects to load and manipulate CSV,TSV,etc files.

As for creating Office documents this is something that if you want easy conversion you will have to pay for. It is only really used in commercial applications so library writers know that there is a market for this.

That said there are some free libraries out there and I have heard good things about this one for editing Excel files:

樱娆 2024-12-31 03:54:21

我使用 Office 的 COM 互操作做了很多类似的事情。我的建议是查看以下链接:

http://msdn.microsoft.com /en-us/library/dd264733.aspx

它应该可以帮助您启动并运行它。如果您有任何具体问题,请告诉我。

I have done a lot of stuff like this using COM interop for Office. My recommendation is to check out the following link:

http://msdn.microsoft.com/en-us/library/dd264733.aspx

It should get you up and running with it. Let me know if you have any specific questions.

回梦 2024-12-31 03:54:21

您可以尝试使用开源库EPPlus来生成excel文件。它比完整的 Excel 应用程序更容易部署。

You can try the open source library EPPlus to generate excel files. It's easier to deploy than the full Excel application.

萝莉病 2024-12-31 03:54:21

您可以尝试 GroupDocs.Conversion REST API,用于 TSV 到 Excel 或 Excel 到 TSV 转换。您可以通过任何 REST 客户端或适用于 .NET 的 GroupDocs.Conversion Cloud SDK 使用它。请注意,它是一个付费 API,但其免费计划每月提供 150 次免费 API 调用。

PS:我是 GroupDocs 的开发人员布道者。

// Get Client Id and Client Key from https://dashboard.groupdocs.cloud/
var configuration = new GroupDocs.Conversion.Cloud.Sdk.Client.Configuration(ClientId, ClientKey);
var fileApi = new GroupDocs.Conversion.Cloud.Sdk.Api.FileApi(configuration);
var convertApi = new ConvertApi(configuration);

// Convert TSV to XLSX
var format = "xlsx";
var testFile = "C:/Temp/sample.tsv";

var request = new ConvertDocumentDirectRequest(format, File.OpenRead(testFile));
var result = convertApi.ConvertDocumentDirect(request);

// Save output to local drive
var fileStream = System.IO.File.Create("C:/Temp/sample.xlsx");
result.CopyTo(fileStream);

You can give it a try on GroupDocs.Conversion REST API for TSV to Excel or Excel to TSV conversion. You can use it via any REST Client or GroupDocs.Conversion Cloud SDK for .NET. Please note it is a paid API but its free plan offers free 150 API calls per month.

P.S: I am developer evangelist at GroupDocs.

// Get Client Id and Client Key from https://dashboard.groupdocs.cloud/
var configuration = new GroupDocs.Conversion.Cloud.Sdk.Client.Configuration(ClientId, ClientKey);
var fileApi = new GroupDocs.Conversion.Cloud.Sdk.Api.FileApi(configuration);
var convertApi = new ConvertApi(configuration);

// Convert TSV to XLSX
var format = "xlsx";
var testFile = "C:/Temp/sample.tsv";

var request = new ConvertDocumentDirectRequest(format, File.OpenRead(testFile));
var result = convertApi.ConvertDocumentDirect(request);

// Save output to local drive
var fileStream = System.IO.File.Create("C:/Temp/sample.xlsx");
result.CopyTo(fileStream);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文