How to convert xlsx files into 2003 xls files programatically in C#?

前端 未结 4 1718
遥遥无期
遥遥无期 2021-01-03 12:39

I\'ve found ExcelPackage, a better library than Excel Interop API to create and mantain programatically excel sheets, but they are generated in .xlsx. Most of people that wi

4条回答
  •  情歌与酒
    2021-01-03 13:23

    Try this code:

            try
            {
                Microsoft.Office.Interop.Word.ApplicationClass oWord = new ApplicationClass();
                object oMissing = Type.Missing;
                object fileName = @"c:\test.docx";
                Document oDoc = oWord.Application.Documents.Open(ref fileName, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
                object fileName2 = @"c:\test2.doc";
    
                object fileFormat = WdSaveFormat.wdFormatDocument97;
                oDoc.SaveAs(ref fileName2, ref fileFormat, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
    
                oDoc.Close(ref oMissing, ref oMissing, ref oMissing);
                oWord = null;
                Console.WriteLine("Done");
    
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            Console.Read();
    

提交回复
热议问题