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; case ".ODS": ef.LoadOds(args[0], OdsOptions.None); break; default: throw new Exception("You must specify input file name with a valid extension (.XLS, .CSV, .XLSX or .ODS)."); } 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; case ".ODS": ef.SaveOds(args[1]); break; default: throw new Exception("You must specify output file name with a valid extension (.XLS, .CSV, .XLSX or .ODS)."); } Console.WriteLine("\n " + args[0] + " converted to " + args[1]); } } } }