show multi-line text value in cells of an XML excel document made with C# XmlWriter

10,376

If you create a simple Excel file with some multi-line contant and save as XML you can see this in the output:

In the tag

<Style ss:ID="s62">
   <Alignment ss:Vertical="Bottom" ss:WrapText="1"/>
</Style>

Cell XML:

<Cell ss:StyleID="s62"> <Data ss:Type="String">First Line&#10;Second Line&#10;Last Line</Data> </Cell>

Share:
10,376
Adamantine
Author by

Adamantine

Updated on June 05, 2022

Comments

  • Adamantine
    Adamantine almost 2 years

    The Situation: I'm creating a C# .Net 4.0 Winform to collect a datatable from an Oracle DB using filters chosen by the user and putting them into a Gridview Preview to check out. Once they have filtered the data to their liking they click an export button which converts the datatable into an XML document that opens in Excel when double clicked. Inside the XML excel file each record looks like so:

      <ss:Row>
        <ss:Cell ss:StyleID="General">
          <ss:Data ss:Type="String">110002</ss:Data>
        </ss:Cell>
        <ss:Cell ss:StyleID="General">
          <ss:Data ss:Type="String">GALV.047M X 3 G90 A653 PASSDRY SQ GR33</ss:Data>
        </ss:Cell>
        <ss:Cell ss:StyleID="General">
          <ss:Data ss:Type="String">.047 MIN X 3 X COIL
    !GALV G90 ASTM A 653 SQ GR33 PASS DRY*
    
    20" ID
    5 TON MAX LIFT
    SKID EYE TO THE SKY
    3" X 3" SPACER IN BETWEEN EACH BUNDLE
    SUPPLY TEST REPORTS CHEMICAL</ss:Data>
        </ss:Cell>
      </ss:Row>
    

    Which displays records in excel similar to how you would seem them if the file were a CVS, a completly unformatted worksheet with all text on a single line. Clearly inside the XML file the line breaks are preserved, but the excel sheet is meant for users to edit the data so I need to display the text how I recieve it (ie. on multiple lines if that is the case).

    The Question: How can I format the exported XML file to display it's cell contents on multiple lines (and perhaps increase cell hight to match) if that is how the data in the XML file is formatted?