For opening a file, you don't need a file format. So you dont have to give a value. But the catch is this method does not allow nulls. Hence the work around is create a missing variable and send it as parameter. Or just give this System.Reflection.Missing.Value and try.
Sridaran Sriram
Posts
-
Excel file format saving as XMLSpreadsheet [modified] -
Excel file format saving as XMLSpreadsheet [modified]Hi, I have to insert a logo in the excel file which is created using CreateText() method of file stream. After writing XML data in the file, I open the excel to insert a logo at the end. It is opening the excel and pasting the logo perfectly. But the problem is it is not saved properly. I have given my code below. Excel.Application excelApplication = null; Excel._Workbook workbook; excelApplication = new Excel.ApplicationClass(); string fname = "D:\\datapointlogo.bmp"; object missing = System.Reflection.Missing.Value; excelApplication.Visible = true; excelApplication.UserControl = true; workbook = excelApplication.Workbooks.Open(fileName, missing, missing, 5 , missing, missing , missing, missing, missing, missing, missing, missing, missing, missing, missing); Excel.Worksheet ThisSheet = (Excel.Worksheet)workbook.Sheets[1]; Excel.Range oRange = (Excel.Range)ThisSheet.Cells[35, 1]; Image oImage = Image.FromFile(fname); oRange.set_Item(35, 1, oImage); System.Windows.Forms.Clipboard.SetDataObject(oImage, true); ThisSheet.Paste(oRange, fname); workbook.Save(); After opening the excel file, I noticed that, File format for this excel is XMLSpreadsheet. I tried to manually change the file format in the Save As dialog and it worked fine. Also, Please note that, I don't want to use the following line though it works fine. workbook.SaveAs(fileName, Excel.XlFileFormat.xlExcel8, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, Excel.XlSaveAsAccessMode.xlNoChange, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value); I have to change the file format without using SaveAs method. Please help me. Thanks, S.Sriram.
modified on Monday, November 17, 2008 4:02 AM