Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 99825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:27:43+00:00 2026-05-11T00:27:43+00:00

I am running into the same problem as in this question: How do you

  • 0

I am running into the same problem as in this question:

How do you prevent leading zeros from being stripped when importing an excel doc using c#

But I am not sure if that is the best solution for my scenario. Here is the code I am using to do the export. Does anyone know what I can change to prevent the leading 0’s from being stripped off?

private static void Export_with_XSLT_Web(DataSet dsExport,                                           string[] sHeaders,                                           string[] sFileds,                                           ExportFormat FormatType,                                           string FileName) {          HttpContext.Current.Response.Clear();         HttpContext.Current.Response.Buffer = true;          HttpContext.Current.Response.ContentType = 'application/vnd.ms-excel';         HttpContext.Current.Response.AppendHeader('content-disposition',                                                    'attachment;                                                    filename=' + FileName);         }          // XSLT to use for transforming this dataset.                                MemoryStream stream = new MemoryStream();         XmlTextWriter writer = new XmlTextWriter(stream, Encoding.UTF8);          CreateStylesheet(writer, sHeaders, sFileds, FormatType);         writer.Flush();         stream.Seek(0, SeekOrigin.Begin);          XmlDataDocument xmlDoc = new XmlDataDocument(dsExport);         XslTransform xslTran = new XslTransform();         xslTran.Load(new XmlTextReader(stream), null, null);          using(StringWriter sw = new StringWriter())         {             xslTran.Transform(xmlDoc, null, sw, null);              HttpContext.Current.Response.Write(sw.ToString());                             writer.Close();             stream.Close();             HttpContext.Current.Response.End();         }     } } 

Here is the method that creates the stylesheet, is there anything in here that I can change to bring in some or all fields as text.

private static void CreateStylesheet(XmlTextWriter writer,                                       string[] sHeaders,                                       string[] sFileds,                                       ExportFormat FormatType) {     try     {         // xsl:stylesheet         string ns = 'http://www.w3.org/1999/XSL/Transform';         writer.Formatting = Formatting.Indented;         writer.WriteStartDocument();         writer.WriteStartElement('xsl', 'stylesheet', ns);         writer.WriteAttributeString('version', '1.0');         writer.WriteStartElement('xsl:output');         writer.WriteAttributeString('method', 'text');         writer.WriteAttributeString('version', '4.0');         writer.WriteEndElement();          // xsl-template         writer.WriteStartElement('xsl:template');         writer.WriteAttributeString('match', '/');          // xsl:value-of for headers         for(int i = 0; i < sHeaders.Length; i++)         {             writer.WriteString('\'');             writer.WriteStartElement('xsl:value-of');             writer.WriteAttributeString('select', ''' + sHeaders[i] + ''');             writer.WriteEndElement(); // xsl:value-of             writer.WriteString('\'');         }          // xsl:for-each         writer.WriteStartElement('xsl:for-each');         writer.WriteAttributeString('select', 'Export/Values');         writer.WriteString('\r\n');          // xsl:value-of for data fields         for(int i = 0; i < sFileds.Length; i++)         {             writer.WriteString('\'');             writer.WriteStartElement('xsl:value-of');             writer.WriteAttributeString('select', sFileds[i]);             writer.WriteEndElement(); // xsl:value-of             writer.WriteString('\'');         }          writer.WriteEndElement(); // xsl:for-each         writer.WriteEndElement(); // xsl-template         writer.WriteEndElement(); // xsl:stylesheet         writer.WriteEndDocument();     }     catch(Exception Ex)     {         throw Ex;     } } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T00:27:43+00:00Added an answer on May 11, 2026 at 12:27 am

    I don’t know the output of your XSL transformation: I will assume it’s the xml format for Excel. Trying to reverse the process I wrote three numbers (007) in an Excel sheet: once as number, once as text and once as number but formatted to show 3 digits padded with zeros. Then I saved it as xml and looked at it. Here is the fragment:

    <Row>     <Cell><Data ss:Type='Number'>7</Data></Cell> </Row> <Row>     <Cell><Data ss:Type='String' x:Ticked='1'>007</Data></Cell> </Row> <Row>     <Cell ss:StyleID='s22'><Data ss:Type='Number'>7</Data></Cell> </Row> 

    I’m not copying the style but you can easily do it.

    Edit: as always Google Is Your Friend (and mine, too 😉 ): http://www.creativyst.com/Doc/Articles/CSV/CSV01.htm#CSVAndExcel.

    Edit (2): I thought the link was enough. The article is saying that (if you are sure the target is only Excel) you can use an Excel-specific CSV syntax. So in your case and looking at your code I think you should insert the missing commas and change the opening

    writer.WriteString('\''); 

    into

    writer.WriteString('=\''); 

    Beware that I didn’t try.

    Just one question out of curiosity: wouldn’t it be simpler to just output what you need working on the DataSet instead of

    • transforming it in XML
    • generating an ad-hoc XSL
    • performing the XSL transformation
    • copying the result to the Response stream

    ?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 80k
  • Answers 80k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer use this listener in your web.xml: <listener> <listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class> </listener> May 11, 2026 at 4:19 pm
  • Editorial Team
    Editorial Team added an answer When you render the partial view, use the ViewData["Category"] as… May 11, 2026 at 4:19 pm
  • Editorial Team
    Editorial Team added an answer In your .ssh/config, set something like: Host somehost IdentityFile /path/to/extra_secret_key… May 11, 2026 at 4:19 pm

Related Questions

I am trying to do positioning in JavaScript. I am using a cumulative position
I am currently using an image manipulation script to do some work on uploaded
I'm trying to implement optional parameters in a stored procedure that I have but
I have an IE BHO that's in development in C#. It is supposed to

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.