简体   繁体   English

在使用C#XmlWriter创建的XML excel文档的单元格中显示多行文本值

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

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. 情况:我正在创建一个C#.Net 4.0 Winform,使用用户选择的过滤器从Oracle DB收集数据表,并将它们放入Gridview预览中检出。 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. 一旦他们根据自己的喜好过滤了数据,他们会点击一个导出按钮,将数据表转换为双击时在Excel中打开的XML文档。 Inside the XML excel file each record looks like so: 在XML excel文件中,每条记录都是这样的:

  <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. 其中显示excel中的记录,类似于文件是CVS时的样子,这是一个完整无格式的工作表,所有文本都在一行上。 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). 显然,在XML文件中保留了换行符,但excel表用于编辑数据,因此我需要显示文本如何收到它(即如果是这样的话,在多行上)。

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? 问题:如果格式化XML文件中的数据,我如何格式化导出的XML文件以在多行上显示单元格内容(并且可能增加单元格高度以匹配)?

If you create a simple Excel file with some multi-line contant and save as XML you can see this in the output: 如果您创建一个包含多行的简单Excel文件并另存为XML,您可以在输出中看到:

In the tag 在标签中

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

Cell XML: Cell XML:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM