none
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);
    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.
    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.

          Thanks,

    Best Regards,
    Lingzhi
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. http://forums.msdn.microsoft.com/en-US/csharpide/thread/8e9ed0d7-11ff-402a-8489-9b5f05eeb706 http://forums.msdn.microsoft.com/en-US/vssetup/thread/60424309-bd78-4ca2-b618-03c4a16123b6
    Thursday, November 20, 2008 7:20 AM
    Moderator