Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Excel file format saving as XMLSpreadsheet [modified]

Excel file format saving as XMLSpreadsheet [modified]

Scheduled Pinned Locked Moved C#
helpxml
3 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sridaran Sriram
    wrote on last edited by
    #1

    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

    W 1 Reply Last reply
    0
    • S Sridaran Sriram

      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

      W Offline
      W Offline
      Wolfram Steinke
      wrote on last edited by
      #2

      I'd like to use that line in my in my app, however EXcel give an exception if I specify a fileformat other then missing.

      Happy programming!!

      S 1 Reply Last reply
      0
      • W Wolfram Steinke

        I'd like to use that line in my in my app, however EXcel give an exception if I specify a fileformat other then missing.

        Happy programming!!

        S Offline
        S Offline
        Sridaran Sriram
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups