ConvertCS
|
|
using System;
using System.IO;
using GemBox.Spreadsheet;
namespace Samples
{
/// <summary>
/// Conversion sample.
/// </summary>
class Convert
{
[STAThread]
static void Main(string[] args)
{
// TODO: If using GemBox.Spreadsheet Professional, put your serial key below.
// Otherwise, if you are using GemBox.Spreadsheet Free, comment out the
// following line (Free version doesn't have SetLicense method).
// SpreadsheetInfo.SetLicense("YOUR-SERIAL-KEY-HERE");
if (args.Length != 2)
Console.Write("\n ConvertCS[.exe] InputFile OutputFile\n");
else
{
ExcelFile ef = new ExcelFile();
switch (Path.GetExtension(args[0]).ToUpper())
{
case ".XLS":
ef.LoadXls(args[0]);
break;
case ".CSV":
ef.LoadCsv(args[0], CsvType.CommaDelimited);
break;
case ".XLSX":
ef.LoadXlsx(args[0], XlsxOptions.None);
break;
default:
throw new Exception("You must specify input file name with a valid extension (.XLS, .CSV or .XLSX).");
}
switch (Path.GetExtension(args[1]).ToUpper())
{
case ".XLS":
ef.SaveXls(args[1]);
break;
case ".CSV":
ef.SaveCsv(args[1], CsvType.CommaDelimited);
break;
case ".XLSX":
ef.SaveXlsx(args[1]);
break;
default:
throw new Exception("You must specify output file name with a valid extension (.XLS, .CSV or .XLSX).");
}
Console.WriteLine("\n " + args[0] + " converted to " + args[1]);
}
}
}
}
| |
|
|
Convert XLS To CSV with Spreadsheet Component . NET
|