简体   繁体   English

使用C#导出到Excel中的问题

[英]Issue in Export to Excel using C#

I'm developin a web application. 我正在开发一个Web应用程序。 I need to export the dataset to excel. 我需要将数据集导出到excel。 The Dataset contains the following text in one column. 数据集在一列中包含以下文本。

Text in Dataset 数据集中的文字

Employee Benefit Sales – Group Benefit Sales 员工福利销售–团体福利销售

When I exported this dataset to excel, all other dataset column values are exported as such in dataset. 当我将此数据集导出到excel时,所有其他数据集列值也将在数据集中导出。 But this text alone got appended with special character as follows. 但是,仅此文本就附加了以下特殊字符。

Text exported with Special Character 以特殊字符导出的文本

Employee Benefit Sales – Group Benefit Sales 员工福利销售–团体福利销售

I don't know how this happens. 我不知道这是怎么发生的。

Help me how to solve this issue. 帮助我如何解决此问题。

The problem MIGHT be an encoding problem. 该问题可能是编码问题。

Since we don't know how you're exporting the dataset to excel we can only assume you are creating a file or stream. 由于我们不知道如何将数据集导出到excel,因此只能假定您正在创建文件或流。

You'll need to add a UTF8 BOM to the beginning of file/stream: 您需要将UTF8 BOM添加到文件/流的开头:

Encoding.UTF8.GetPreamble()

See this for more information. 请参阅以获取更多信息。

如果尚未指定encoding则应这样做:

Response.ContentEncoding = System.Text.Encoding.UTF8;

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

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