Hi,
I have a strange but reproducible problem when creating a workbook from a csv using TxtLoadOptions.PreferredParsers.
My first column is in quotes and I want it to be treaded as a string and I have a customer parser for it. The second column has a date not in quotes.
"23/09/2018",22/09/2018
In the scenario above, the first becomes a string and the second column becomes a date.
"22/09/2018",22/09/2018
However, if the second column has the same value as the first, it makes column one and two both strings. It seems to say, hey this column has the same value as one of the previous ones in this row, I’ll assume the column type is the same even though they have different parsers.
This definitely seems like a bug to me. Any have an thoughts/ideas?
Full code below.
Thanks
fxm
class Program
{
static void Main(string[] args)
{
LoadFormat oLoadFormat = LoadFormat.Excel97To2003;
TxtLoadOptions oTxtLoadOptions = new TxtLoadOptions(oLoadFormat);
oTxtLoadOptions.Separator = Convert.ToChar(",");
oTxtLoadOptions.Encoding = System.Text.Encoding.UTF8;
oTxtLoadOptions.ConvertDateTimeData = true;
ICustomParser[] oCustomParser = new ICustomParser[2];
oCustomParser[0] = new TextParser();
oTxtLoadOptions.PreferredParsers = oCustomParser;
Aspose.Cells.Workbook oExcelWorkBook = new Aspose.Cells.Workbook("testOk.csv", oTxtLoadOptions);
Console.WriteLine("testOk.csv"); //"23/09/2018",22/09/2018
Aspose.Cells.Cell oCell = oExcelWorkBook.Worksheets[0].Cells["A1"];
Console.WriteLine("A1: " + oCell.Type.ToString() + " - " + oCell.DisplayStringValue);
oCell = oExcelWorkBook.Worksheets[0].Cells["B1"];
Console.WriteLine("B1: " + oCell.Type.ToString() + " - " + oCell.DisplayStringValue);
Console.WriteLine("");
Console.WriteLine("");
oExcelWorkBook = new Aspose.Cells.Workbook("testNotOk.csv", oTxtLoadOptions);
Console.WriteLine("testNotOk.csv"); //"22/09/2018",22/09/2018
oCell = oExcelWorkBook.Worksheets[0].Cells["A1"];
Console.WriteLine("A1: " + oCell.Type.ToString() + " - " + oCell.DisplayStringValue);
oCell = oExcelWorkBook.Worksheets[0].Cells["B1"];
Console.WriteLine("B1: " + oCell.Type.ToString() + " - " + oCell.DisplayStringValue);
Console.ReadKey();
}
}
class TextParser : ICustomParser
{
public object ParseObject(string value)
{
return value;
}
public string GetFormat()
{
return "";
}
}