相关疑难解决方法(0)

将Excel文件从.csv转换为.xlsx

我希望我的应用程序去找一个 excel文件并将其转换为.xlsx文件.

这就是我目前正在做的事情;

var fileName = @"Z:\0328\orders\PurchaseOrder.csv";
FileInfo f = new FileInfo(fileName);
f.MoveTo(Path.ChangeExtension(fileName, ".xlsx"));
var Newfile = @"Z:\0328\orders\PurchaseOrder.xlsx";
Run Code Online (Sandbox Code Playgroud)

现在这确实有效.它将文件扩展名更改为我想要的格式.然而,该文件然后变得"腐败"或至少Excel拒绝打开它,当我尝试进一步冒险时我的应用程序也不会.

有没有人有解决方案/解决方案?

c# winforms

15
推荐指数
3
解决办法
6万
查看次数

C#将csv转换为xls(使用现有的csv文件)

我相信这里有很多关于此事的讨论.但我读了所有帖子并尝试但它从未与c#一起工作.我的目标很简单,我有现有的csv文件.只想转换exel文件并完成.很多人说使用spire.xls,但我相信MS .office.interop.excel可以处理它.

将Excel文件从.csv转换为.xlsx

我读了上面的问题,这跟我的问题一样.但上面的代码不能在我的电脑上工作..我需要导入其他DLL才能使用它.我只是从该网站复制代码.再次复制下面......

目前我使用Lib作为MS.office.interop.excel和MS.office.interop.core

Application app = new Application();
Workbook wb = app.Workbooks.Open(@"C:\testcsv.csv", Type.Missing, Type.Missing,               Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
wb.SaveAs(@"C:\testcsv.xlsx", XlFileFormat.xlOpenXMLWorkbook, Type.Missing,    Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
wb.Close();
app.Quit();
Run Code Online (Sandbox Code Playgroud)

这里有很多错误.修改代码在下面,现在我只在我的参考中使用MS.office.interop.excel和MS.office.interop.core.看起来我需要使用另一个dll文件.无论如何,我确实遵循该代码并制作新代码.它减少了错误,但我不知道这是正确的方法.以下是我现在尝试的.

        Excel.Application xlApp;
        Excel.Workbook xlWorkBook;
        Excel.Worksheet xlWorkSheet;
        object misValue = System.Reflection.Missing.Value;

        System.Globalization.CultureInfo oldCI = System.Threading.Thread.CurrentThread.CurrentCulture;
        System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");

        xlApp = new Excel.ApplicationClass();
        xlWorkBook = xlApp.Workbooks.Add(misValue);

        xlWorkBook = xlApp.Workbooks.Open(@"C:\testcsv.csv", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, …
Run Code Online (Sandbox Code Playgroud)

.net c# csv excel converter

14
推荐指数
1
解决办法
5万
查看次数

C#Excel将数据从CSV导入Excel

如何使用C#从CSV文件导入Excel中的数据?实际上,我想要实现的与我们在Excel中的操作类似,您可以转到" 数据"选项卡,然后选择" 从文本"选项,然后使用" 文本到列"选项并选择"CSV",它可以实现神奇的功能.我想自动化它.

如果你能让我朝着正确的方向前进,我会非常感激.

编辑:我想我没有解释清楚.我想做的就像是

Excel.Application excelApp;
Excel.Workbook excelWorkbook;

// open excel
excelApp = new Excel.Application();

// something like
excelWorkbook.ImportFromTextFile(); // is what I need
Run Code Online (Sandbox Code Playgroud)

我想将这些数据导入Excel,而不是我自己的应用程序.据我所知,我不认为我必须自己解析CSV然后将它们插入Excel中.Excel为我们做到了这一点.我只需要知道如何自动化该过程.

c# csv import excel vsto

8
推荐指数
2
解决办法
4万
查看次数

标签 统计

c# ×3

csv ×2

excel ×2

.net ×1

converter ×1

import ×1

vsto ×1

winforms ×1