如何在C#中将.HTML文件内容复制到.XLSX文件? [英] How to copy a .HTML file content to a .XLSX file in C# ?

查看:79
本文介绍了如何在C#中将.HTML文件内容复制到.XLSX文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我可以创建.XLSX格式的文件.在这里,我使用 File.Copy().通过这种方法,我将.HTML格式的文件作为Source&目标是.XLSX格式的文件.此方法能够将.HTML格式的文件中的所有数据内容复制到.XLSX格式的文件中.但是它创建了一个缩小的.XLSX格式的文件.因此,当我在OFFICE 2007中打开此创建的文件时,我收到了错误的简报文件.但是,如果我将相同文件的格式手动修改为.XLS,则可以在Office 2007中打开(只需给出版本消息并正确打开文件即可).

在这里,我如何使用这种方法-
File.Copy( @"C:\\ Program Files \\ Proj \\ Configurations \\ XYZ.html" @"C:\\ Program Files \\ Proj \\ Configurations \ \ ABC.xlsx" true );

ProcessStartInfo startInfo =新的ProcessStartInfo("Excel.exe");
startInfo.Arguments =''''+" C:\\ Program Files \\ Proj \\ Configurations \\ ABC.xlsx"+"'';
Process.Start(startInfo); //会打开此"ABC.xlsx"文件


我认为"File.Copy()"不支持此.XLSX格式进行复制.我也使用了"File.Move()",但发生了同样的事情.

请尽快帮助我.
预先感谢:)

Hi,
I''m able to create a .XLSX formated file .Here i''m using File.Copy().In this method i''m passing .HTML formatted file as Source & Destination as a .XLSX formatted file. This method able to copy all the data content in .HTML formatted file to .XLSX formatted file. But it creating a curropted .XLSX formatted file. So while i''m opening this created file in OFFICE 2007 i''m geting error as a curropted file. But if i manually modify the same file''s format to .XLS ,i can able to open in Office 2007(Just giving an version message & opening the file properly).

Here how i''m using this method -
File.Copy( @"C:\\Program Files\\Proj\\Configurations\\XYZ.html" , @"C:\\Program Files\\Proj\\Configurations\\ABC.xlsx" , true);

ProcessStartInfo startInfo = new ProcessStartInfo("Excel.exe");
startInfo.Arguments = ''"'' + "C:\\Program Files\\Proj\\Configurations\\ABC.xlsx" + ''"'';
Process.Start(startInfo); // It opens this ''ABC.xlsx'' file


I think " File.Copy()" is not supporting this .XLSX format for copying purpose.I used also " File.Move()" , but same thing happening.

Kindly please help me soon.
Thanks in advance :)

推荐答案

到底是什么让您认为可以复制HTML文件,将其重命名为XLSX文件,这将使它打开-可以通过Excel进行操作吗?
这就像在说:如果我更换福特Ka上的徽章,它将真的变成一辆布加迪威龙."
What on earth makes you think that you can copy an HTML file, renaming it to an XLSX file and that that will make it open-able by Excel?

That is like saying "If I change the badges on my Ford Ka, it will really become a Bugatti Veyron."


这篇关于如何在C#中将.HTML文件内容复制到.XLSX文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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