我使用aspose.cell以“,”作为列分隔符&读取我的csv文件。单引号(')作为文本限定符& newline as row delimiter。看起来如下: 例如:
'1'。 '2', '3', '4'
'5', '6', '7', '8'
1',2',3',4'
5',6',7',8'
文本限定符为双引号(“)时没有问题。
有人可以帮助一个,如何将我的csv文件与单引号(')作为文本限定符与aspose.cell ?
谢谢
TxtLoadOptions options = new TxtLoadOptions( LoadFormat.CSV)
options.ConvertNumericData = false;
options.ConvertDateTimeData = false;
options.SeparatorString=",";
// reading aspose license reading, code removed
//stream is ----stream reader
Workbook workBook = new Workbook(stream, options);
workBook.Settings.CheckExcelRestriction = false;
var workSheet = workBook.Worksheets[workBook.Worksheets.ActiveSheetIndex];
Console.WriteLine( workSheet.Cells[0, 0].Value.ToString());
Console.WriteLine( workSheet.Cells[0, 1].Value.ToString());
Console.WriteLine( workSheet.Cells[0, 2].Value.ToString());
Console.WriteLine( workSheet.Cells[0, 3].Value.ToString());
Console.WriteLine( workSheet.Cells[1, 0].Value.ToString());
Console.WriteLine( workSheet.Cells[1, 1].Value.ToString());
Console.WriteLine( workSheet.Cells[1, 2].Value.ToString());
Console.WriteLine( workSheet.Cells[1, 3].Value.ToString());
答案 0 :(得分:0)
将TxtLoadOptions与CSV文件一起使用时似乎是一个问题。您可以尝试使用LoadOptions而不是TxtLoadOptions打开您的csv文件,没有任何问题。您可以参考以下代码:
Aspose.Cells.LoadOptions options = new Aspose.Cells.LoadOptions(Aspose.Cells.LoadFormat.CSV);
options.ConvertNumericData = false;
Workbook workBook = new Workbook("C:\\Data\\open.csv", options);
workBook.Settings.CheckExcelRestriction = false;
var workSheet = workBook.Worksheets[workBook.Worksheets.ActiveSheetIndex];
Console.WriteLine( workSheet.Cells[0, 0].Value.ToString());
Console.WriteLine( workSheet.Cells[0, 1].Value.ToString());
Console.WriteLine( workSheet.Cells[0, 2].Value.ToString());
Console.WriteLine( workSheet.Cells[0, 3].Value.ToString());
Console.WriteLine( workSheet.Cells[1, 0].Value.ToString());
Console.WriteLine( workSheet.Cells[1, 1].Value.ToString());
Console.WriteLine( workSheet.Cells[1, 2].Value.ToString());
Console.WriteLine( workSheet.Cells[1, 3].Value.ToString());
希望这有帮助。