有什么方法可以指定SpreadsheetGear中用于生成CSV文件的编码? [英] Is there any way to specify the encoding used in SpreadsheetGear to generate CSV files?

查看:47
本文介绍了有什么方法可以指定SpreadsheetGear中用于生成CSV文件的编码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Spreadsheet Gear将包含Unicode字符的数据从我们的系统中导出为csv格式.(适合Excel).

I am trying to export data containing Unicode characters from our system using Spreadsheet Gear to csv format. (Fine for excel).

但是,由于CSV格式不是UTF-8编码的,因此所有Unicode字符都导出为???

However because the CSV format is not UTF-8 encoded all the Unicode characters are exported as ???

我知道Spreadsheet Gear通过使用制表符分隔的UTF-8文本文件来支持Unicode,但是我们需要用逗号分隔的文件.

I am aware that Spreadsheet Gear supports Unicode by having a tab-delimited UTF-8 text file, however we require the comma-delimited file.

这是当前存在的内容(包括我检查Unicode文本文件格式是否正确导出了字符):

This is what currently exists (including my check that the Unicode Text file format exports the characters correctly):

public static void ExportToStream(Stream stream, IDataSource data, IEnumerable<ColumnInfo> columns, ExportFormat format)
    {
        var exporter = new ExportCreator
        {
            Data = data,
            Columns = columns.ToArray(),
            EscapeFormulas = format == ExportFormat.Xlsx
        };
        var workbook = exporter.GetWorkBookForExport();
        switch (format)
        {
            //need to put something in here to enable the csv to be encoded as utf-8 - 
            //currently spreadsheet gear only supports utf-8 encoded tab delimited text file
            case ExportFormat.Csv:
                workbook.SaveToStream(stream, FileFormat.UnicodeText);
                break;
            case ExportFormat.Xlsx:
                workbook.SaveToStream(stream, FileFormat.OpenXMLWorkbook);
                break;
        }
    }

据我从拖延Spreadsheet Gear文档和SO所知,UnicodeText格式可以解决问题,但不满足我们对CSV文件格式的要求.

As far as I can tell from trawling the Spreadsheet Gear documentation and SO, UnicodeText format would solve the problem but doesn't meet our requirements for the CSV file format.

是否可以指定流的编码,以便将CSV文件格式保存为UTF-8编码?

Is there a way of specifying the encoding of the stream so the CSV File format is saved as UTF-8 encoded?

推荐答案

SpreadsheetGear没有提供用于指定CSV文件编码的选项,也没有指定用于给定基于文本的数据文件使用什么定界符的选项.如果您有使用UTF编码的CSV,则需要构建自己的例程来相应地读取和处理此文件,然后将这些数据逐个单元手动插入工作表中.

SpreadsheetGear provides no option to specify the encoding of a CSV file, or option to specify what delimiter is used for a given text-based data file. If you have a CSV encoded with UTF, you would need to build your own routine that reads and handles this file accordingly, then manually insert that data into your worksheet cell-by-cell.

这篇关于有什么方法可以指定SpreadsheetGear中用于生成CSV文件的编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆