Excel cell text is trimmed when writen in xlsx file when using C# & OpenXML -
when writing inside excel file text in cell gets trimmed after writing.
for example:
let's trying write :"\r\nthis text starts new line "
expect when open xlsx file cell start empty line, instead "this text starts new line"
this happens whitespace @ beginning , end, gets trimmed.
i have tried setting cell format doesn't seem work:
new cellformat() { applyalignment = true, alignment = new alignment { wraptext = new booleanvalue(false) } }
the problem underlying format xml. whitespace @ start or end of value ignored unless mark space preserved.
to need set space
property spaceprocessingmodevalues.preserve
, example:
cell cell = new cell() { cellreference = "a1" }; cellvalue value = new cellvalue("\r\nthis text starts new line"); value.space = spaceprocessingmodevalues.preserve; cell.cellvalue = value; cell.datatype = new enumvalue<cellvalues>(cellvalues.string);
this produces xml looks like:
<x:c r="a1" t="str"> <x:v xml:space="preserve"> text starts new line</x:v> </x:c>
the xml:space="preserve"
prevent whitespace being removed beginning or end of value. produces file looks below can see newline preserved.
Comments
Post a Comment