public static string GPSSORT_Main(string dataPath, string savePath, string fileName) { outPutTxt = ""; EXCEL Excel = new EXCEL(Path.Combine(dataPath, fileName)); //string[,] data = ExcelClass.ExcelSaveAndRead.Read(Path.Combine(dataPath, fileName), 1, 1, 1); string[,] data = Excel.GetDataBySheetName(1, 1, Excel.sheets[0]); string[,] excelData = TransToExcelFormat(data); string SaveName = "三次元資料.xlsx"; string sheetName = fileName.Replace(".csv", ""); sheetName = sheetName.Replace(".CSV", ""); //ExcelClass.ExcelSaveAndRead.SaveCreat(strPath: Path.Combine(savePath, SaveName), sheetName: sheetName, poRow: 1, poCol: 1, Data: excelData); Excel.Save_To(Path.Combine(savePath, SaveName), sheetName, 1, 1, excelData); outPutTxt = "處理完成\r\n"; Excel.close(); return(outPutTxt); }
private static void Example() { /// 要讀取的Excel檔案名稱 string ExcelName = "sheetData.xlsx"; /// 要另外儲存的Excel檔案名稱 string SaveName = "test.xlsx"; /// 要讀取的Excel檔案路徑 string fPath = Path.Combine(DeskPath, ExcelName); /// 建立Excel 物件 EXCEL Excel = new EXCEL(fPath); /// 取得Excel所有sheet名稱 List <string> sheets = Excel.sheets; /// 讀取第ii個sheet資料,起始位置為(1,1) int ii = 0; string[,] data = Excel.GetDataBySheetName(1, 1, sheets[ii]); /// 讀取所有sheet的資料 Dictionary <string, string[, ]> AllSheetsData = Excel.GetSheetsData(); /// 隨意創立要儲存的資料陣列 string[,] saveData = new string[10, 10]; for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { saveData[i, j] = i.ToString(); } } /// 儲存至所開啟之Excel Excel.Save("儲存資料至本Excel中", 1, 1, saveData); /// 另外儲存的檔案路徑 string savePath = Path.Combine(DeskPath, SaveName); Excel.Save_To(savePath, "儲存資料至其他Excel", 1, 1, saveData); Excel.close(); //////// 顯示資料 /// 顯示所有Sheets ShowSheetsName(sheets); /// 顯示讀取Data Console.WriteLine("========= 第{0}個sheet : {1} 的Data ========= ", ii + 1, sheets[ii]); ShowData(data); /// 顯示所有Sheet資料 ShowAllExcelData(AllSheetsData); }