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. Export to excel /xlsx file

Export to excel /xlsx file

Scheduled Pinned Locked Moved ASP.NET
help
2 Posts 2 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.
  • B Offline
    B Offline
    Ballita
    wrote on last edited by
    #1

    Hi, I need to export file in xlsx format. My code is bellow: string Path = strFullTo + "Balancing_" + String.Format("{0:MMddyy}", DateTime.Now) + ".xlsx"; StringWriter stringWriter = new StringWriter(); HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWriter); GridView DataGrd = new GridView(); System.IO.StreamWriter vw = new System.IO.StreamWriter(Path, true,System.Text.Encoding.Default); stringWriter.ToString().Normalize(); string style = @" .textmode { mso-number-format:\@; } "; vw.Write(style); vw.Write(stringWriter.ToString()); vw.Flush(); vw.Close(); But my problem is when I am trying to open the xlsx file it is saying "File format or extension is not valid". I need to keep the data in xlsx file. Please help.

    Thanks & Regards Mishra

    Z 1 Reply Last reply
    0
    • B Ballita

      Hi, I need to export file in xlsx format. My code is bellow: string Path = strFullTo + "Balancing_" + String.Format("{0:MMddyy}", DateTime.Now) + ".xlsx"; StringWriter stringWriter = new StringWriter(); HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWriter); GridView DataGrd = new GridView(); System.IO.StreamWriter vw = new System.IO.StreamWriter(Path, true,System.Text.Encoding.Default); stringWriter.ToString().Normalize(); string style = @" .textmode { mso-number-format:\@; } "; vw.Write(style); vw.Write(stringWriter.ToString()); vw.Flush(); vw.Close(); But my problem is when I am trying to open the xlsx file it is saying "File format or extension is not valid". I need to keep the data in xlsx file. Please help.

      Thanks & Regards Mishra

      Z Offline
      Z Offline
      ZurdoDev
      wrote on last edited by
      #2

      You need to export as .xls instead of .xlsx. .xlsx is more of an xml format but .xls can support html format, which is essentially what you are doing.

      There are only 10 types of people in the world, those who understand binary and those who don't.

      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