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. Web Development
  3. ASP.NET
  4. Saving Excel from Template urgent

Saving Excel from Template urgent

Scheduled Pinned Locked Moved ASP.NET
sysadmindata-structuresannouncement
1 Posts 1 Posters 0 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
    Suamal
    wrote on last edited by
    #1

    using System.IO; using excel09; using System.Reflection ; using System.Runtime.InteropServices; I am creating a new excel file of version 9 from template of excel 2003. An Image is there in the template file. The excel file is got saved and opened.But image is not getting displayed. Code is Page.Controls.Clear(); Response.ContentType = "application/vnd.ms-excel"; Response.Buffer=true; //To open excel files in lower versions also //Save the byte[] array to xl template file string xlFileName = "Template.xlt"; string xlFilePath = Server.MapPath("../Reports/") + xlFileName; string fileExcel = Server.MapPath("../Reports/" + xlFileName); //template file //Creating instance for excel 9 version //To create excel file in lower version excel09.Application ExcelObj = new excel09.Application(); ExcelObj.Visible = true; xlFileName = "Report - " + System.DateTime.Now.Ticks.ToString() +".xls"; xlFilePath = Server.MapPath("../Reports/") + xlFileName; //Save as file name //Adding template to workbook ExcelObj.Workbooks.Add(fileExcel); Workbooks workbooks = ExcelObj.Workbooks; _Workbook workbook = workbooks.get_Item(1); Sheets sheets = workbook.Worksheets; _Worksheet worksheet = (_Worksheet) sheets.get_Item(1); //Saving excel file in 9 version format workbook.SaveAs(xlFilePath, excel09.XlFileFormat.xlWorkbookNormal,null,null,false,false,excel09.XlSaveAsAccessMode.xlShared,false,false,null,null); workbook.Close(null,null,null); ExcelObj.Workbooks.Close(); ExcelObj.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject (ExcelObj); System.Runtime.InteropServices.Marshal.ReleaseComObject (sheets); System.Runtime.InteropServices.Marshal.ReleaseComObject (workbook); ExcelObj = null; workbook = null; sheets=null; System.GC.Collect(); //Getting from excel version 9 file Response.WriteFile(xlFilePath); Response.Flush(); Response.Buffer=false; Response.End();

    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