c#中的.xls到.xlsx [英] .xls to .xlsx in c#

查看:89
本文介绍了c#中的.xls到.xlsx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在C#..。net framework 3.0中将.xls文件转换为.xlsx



我的代码是这样的:



how to convert a .xls file to .xlsx in C#.. .Net framework 3.0

my code is like this::

if (extension == ".xls")
{
   //1. Reading from a binary Excel file ('97-2003 format; *.xls)
   flpd.SaveAs(filename1);
   stream = File.Open(filename1, FileMode.Open, FileAccess.Read);
   excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
}
else if (extension == ".xlsx")
{
   //2. Reading from a OpenXml Excel file (2007 format; *.xlsx)
   flpd.SaveAs(filename1);
   stream = File.Open(filename1, FileMode.Open, FileAccess.Read);
   excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
}





我的实际问题是,当我在数据库或服务器上的物理位置上传.xls文件时,我的日期值列被改为其他格式,也许是由于这行excelReader = ExcelReaderFactory.CreateBinaryReader(stream);

但是.xlsx工作正常,所以我想转换在上传d文件之前.xls到.xlsx ...

有没有更好的方法...因为我需要为.xls提供选项以及用户



My actual problem is that when i am uploading .xls file in database or on physical location on server ,, my column with date values is getting changed into some other format,,ie maybe due to this line excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
but with .xlsx its working fine, so iwas thinking of converting .xls to .xlsx before uploading d file...
Is there any better way... because i need to give option for .xls as well to d user

推荐答案

您正在谈论第三方工具( http://exceldatareader.codeplex.com/ [ ^ ]) - 以及日期。好吧,步骤信息它的代码并找到发生这种情况的地方 - 如果可以,请修复它。由于日期实际上是特定于语言环境的,因此可能是某处的语言环境问题。
You are talking about a third party tool (http://exceldatareader.codeplex.com/[^])- and about dates. Well, step info it's code and find the place where this is happening - fix it if you can. As dates are really locale-specific, it might be a locale issue somewhere.


private void Excel03to07(string fileName)
        {
            string svfileName = Path.ChangeExtension(fileName, ".xlsx");
            object oMissing = Type.Missing;
            var app = new Microsoft.Office.Interop.Excel.Application();
            var wb = app.Workbooks.Open(fileName, oMissing, oMissing,
                            oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);
            wb.SaveAs(svfileName, XlFileFormat.xlExcel8, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
            app.Quit();
        }


这篇关于c#中的.xls到.xlsx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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