public static tempU::DataTable GetExcel(string filepach, IList <string> filedList, IList <string> capList) { string str; FarPoint.Win.Spread.FpSpread fpSpread1 = new FarPoint.Win.Spread.FpSpread(); try { fpSpread1.OpenExcel(filepach); } catch { string filepath1 = Path.GetTempPath() + "\\" + Path.GetFileName(filepach); File.Copy(filepach, filepath1); fpSpread1.OpenExcel(filepath1); File.Delete(filepath1); } tempU::DataTable dt = new tempU::DataTable(); IList <string> fie = new List <string>(); int m = 3; for (int j = 0; j < fpSpread1.Sheets[0].GetLastNonEmptyColumn(FarPoint.Win.Spread.NonEmptyItemFlag.Data) + 1; j++) { if (capList.Contains(fpSpread1.Sheets[0].Cells[2, j].Text)) { fie.Add(filedList[capList.IndexOf(fpSpread1.Sheets[0].Cells[2, j].Text)]); } } for (int k = 0; k < fie.Count; k++) { dt.Columns.Add(fie[k]); } for (int i = m; i <= fpSpread1.Sheets[0].GetLastNonEmptyRow(FarPoint.Win.Spread.NonEmptyItemFlag.Data); i++) { DataRow dr = dt.NewRow(); for (int j = 0; j < fpSpread1.Sheets[0].GetLastNonEmptyColumn(FarPoint.Win.Spread.NonEmptyItemFlag.Data) + 1; j++) { dr[fie[j]] = fpSpread1.Sheets[0].Cells[i, j].Text; } dt.Rows.Add(dr); } return(dt); }
public static tempU::DataTable GetExcel(string filepach, IList<string> filedList, IList<string> capList) { string str; FarPoint.Win.Spread.FpSpread fpSpread1 = new FarPoint.Win.Spread.FpSpread(); try { fpSpread1.OpenExcel(filepach); } catch { string filepath1 = Path.GetTempPath() + "\\" + Path.GetFileName(filepach); File.Copy(filepach, filepath1); fpSpread1.OpenExcel(filepath1); File.Delete(filepath1); } tempU::DataTable dt = new tempU::DataTable(); IList<string> fie = new List<string>(); int m = 3; for (int j = 0; j < fpSpread1.Sheets[0].GetLastNonEmptyColumn(FarPoint.Win.Spread.NonEmptyItemFlag.Data) + 1; j++) { if (capList.Contains(fpSpread1.Sheets[0].Cells[2, j].Text)) fie.Add(filedList[capList.IndexOf(fpSpread1.Sheets[0].Cells[2, j].Text)]); } for (int k = 0; k < fie.Count; k++) { dt.Columns.Add(fie[k]); } for (int i = m; i <= fpSpread1.Sheets[0].GetLastNonEmptyRow(FarPoint.Win.Spread.NonEmptyItemFlag.Data); i++) { DataRow dr = dt.NewRow(); for (int j = 0; j < fpSpread1.Sheets[0].GetLastNonEmptyColumn(FarPoint.Win.Spread.NonEmptyItemFlag.Data) + 1; j++) { dr[fie[j]] = fpSpread1.Sheets[0].Cells[i, j].Text; } dt.Rows.Add(dr); } return dt; }