Hi justin,
If you want to convert excel worksheet into a csv file, you need a license first.
And then, call SaveToFile/SaveToStream method with a specified separator, for example ,/;/\t etc. Considering internationalization, the result file is saved with Unicode encoding. But different MS-Excel supports different separator and MS-Excel does not support Unicode encoding. So you need do something different.
For Excel 2003:
- Code: Select all
Workbook workbook = new Workbook();
workbook.LoadFromFile(@"DatatableSample.xls");
using (MemoryStream buffer = new MemoryStream())
{
//save to unicode
workbook.SaveToStream(buffer, ",");
buffer.Position = 0;
//convert to ascii
using (StreamReader reader = new StreamReader(buffer))
{
using (StreamWriter writer = File.CreateText("DatatableSample.csv"))
{
String line = null;
while ((line = reader.ReadLine()) != null)
{
writer.WriteLine(line);
}
}
}
}
and for Excel 2010:
- Code: Select all
Workbook workbook = new Workbook();
workbook.LoadFromFile(@"DatatableSample.xls");
using (MemoryStream buffer = new MemoryStream())
{
//save to unicode
workbook.SaveToStream(buffer, ";");
buffer.Position = 0;
//convert to ascii
using (StreamReader reader = new StreamReader(buffer))
{
using (StreamWriter writer = File.CreateText("DatatableSample.csv"))
{
String line = null;
while ((line = reader.ReadLine()) != null)
{
writer.WriteLine(line);
}
}
}
}
and for Excel 2003 & Excel 2010 with multiple languages:
- Code: Select all
Workbook workbook = new Workbook();
workbook.LoadFromFile(@"DatatableSample.xls");
workbook.SaveToFile("DatatableSample3.csv", "\t");