Specify Encoding Format when Export DataTable to Excel with Open Xml SDK in c#

元气小坏坏 提交于 2019-12-24 07:03:10

问题


I am just trying to export datatable as excel using open xml. Referred the below approach,

Export DataTable to Excel with Open Xml SDK in c#

But I couldn't specify the encoding format of the excel created. I want to save or create the excecl with UTF-Encoding-8 format.

Can some one help on how could the formatting specificed using Open XML


回答1:


To save an Excel file with UTF-Encoding-8 Format you need to specify the encoding format under Tools -> Web Options -> Encoding while saving the excel file.

With OpenXML you need to create a new WebPublishing and add it to Workbook.

WebPublishing webPublishing1 = new WebPublishing(){ AllowPng = true, TargetScreenSize = TargetScreenSizeValues.Sz1024x768, CodePage = (UInt32Value)65001U };
workbook1.Append(webPublishing1);
//Where workbook1 is WorkbookPart.Workbook


来源:https://stackoverflow.com/questions/44393927/specify-encoding-format-when-export-datatable-to-excel-with-open-xml-sdk-in-c-sh

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!