Esempio n. 1
0
        public static bool GenerateXls0rCsv(string path, List <List <string> > listList)
        {
            if (listList == null || listList.Count <= 1)//title must exist while no data in file
            {
                string msg = string.Format("no data need to generate");
                throw new Exception(msg);
            }

            using (ExcelApp app = new ExcelApp(false, false))
            {
                try
                {
                    Workbook  wBook  = ExcelUtil.CreateOrOpenExcelFile(app, path);
                    Worksheet wSheet = wBook.Worksheets[1] as Worksheet;
                    FillExcel(wSheet, listList);
                    app.ExcelAppInstance.AlertBeforeOverwriting = false;
                    wBook.Save();
                    return(true);
                }
                catch (Exception ex)
                {
                    string msg = string.Format("generate XlsOrCsv file error ,msg:{0}", ex.ToString());
                    throw new Exception(msg);
                }
            }
        }
Esempio n. 2
0
 public static void ExcelWorksheetToTsv(string excelFilePath, string worksheetName, string textFilePath)
 {
     using (var app = new ExcelApp(false, false))
     {
         var wb = ExcelUtil.CreateOrOpenExcelFile(app, excelFilePath);
         var ws = ExcelUtil.GetWorksheet(worksheetName, wb);
         ws.SaveAs(textFilePath, XlFileFormat.xlUnicodeText,
                   Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
     }
 }