Excel file format saving as XMLSpreadsheet RRS feed

  • Question

  • 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);

    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,

    I have to change the file format without using SaveAs method. Please help me.

    Monday, November 17, 2008 7:21 AM

All replies

  • Hello, 

          I recommend you to consult this question in Discussions in Office Development.   You will get more help from the experts on Office Development there.


    Best Regards,
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Thursday, November 20, 2008 7:20 AM