|
@@ -10,6 +10,10 @@ using Curtain.DataAccess;
|
|
|
using DK.XuWei.WebMes;
|
|
using DK.XuWei.WebMes;
|
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json;
|
|
|
using System.Collections;
|
|
using System.Collections;
|
|
|
|
|
+using System.IO;
|
|
|
|
|
+using NPOI.HSSF.UserModel;
|
|
|
|
|
+using NPOI.SS.UserModel;
|
|
|
|
|
+using NPOI.XSSF.UserModel;
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
/// TP_PM_FQCITEMSDETAIL
|
|
/// TP_PM_FQCITEMSDETAIL
|
|
@@ -169,14 +173,15 @@ public class fqcitemsdetail : IHttpHandler, IReadOnlySessionState
|
|
|
string filePath = "/mes/upload/" + DateTime.Now.ToString("yyyy-MM-dd");
|
|
string filePath = "/mes/upload/" + DateTime.Now.ToString("yyyy-MM-dd");
|
|
|
System.IO.Directory.CreateDirectory(context.Server.MapPath(filePath));
|
|
System.IO.Directory.CreateDirectory(context.Server.MapPath(filePath));
|
|
|
string fileName = filePath + "/检验项目明细" + DateTime.Now.ToString("yyyy-MM");
|
|
string fileName = filePath + "/检验项目明细" + DateTime.Now.ToString("yyyy-MM");
|
|
|
- fileName += System.IO.Path.GetExtension(context.Request.Files[0].FileName+"x");
|
|
|
|
|
|
|
+ fileName += System.IO.Path.GetExtension(context.Request.Files[0].FileName + "x");
|
|
|
string diskFileName = context.Server.MapPath(fileName);
|
|
string diskFileName = context.Server.MapPath(fileName);
|
|
|
if (System.IO.File.Exists(diskFileName)) System.IO.File.Delete(diskFileName);
|
|
if (System.IO.File.Exists(diskFileName)) System.IO.File.Delete(diskFileName);
|
|
|
context.Request.Files[0].SaveAs(diskFileName);
|
|
context.Request.Files[0].SaveAs(diskFileName);
|
|
|
//文件转Table
|
|
//文件转Table
|
|
|
- DataTable detailTable = Import.ExcelToDataTable(diskFileName);
|
|
|
|
|
|
|
+ var detailTable = ExcelToDatatable(diskFileName);
|
|
|
|
|
+ //DataTable detailTable = Import.ExcelToDataTable(diskFileName);
|
|
|
int itemsID = Convert.ToInt32(context.Request["id"]);
|
|
int itemsID = Convert.ToInt32(context.Request["id"]);
|
|
|
- context.Response.Write(Imports(detailTable,itemsID));
|
|
|
|
|
|
|
+ context.Response.Write(Imports(detailTable, itemsID));
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
@@ -1473,5 +1478,70 @@ public class fqcitemsdetail : IHttpHandler, IReadOnlySessionState
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ #region 读取excel数据
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 读取excel数据
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ /// <param name="fileName">地址</param>
|
|
|
|
|
+ /// 李士越 2024-07-01
|
|
|
|
|
+ /// <returns></returns>
|
|
|
|
|
+ public static DataTable ExcelToDatatable(string fileName)
|
|
|
|
|
+ {
|
|
|
|
|
+ ISheet sheet = null;
|
|
|
|
|
+ DataTable datatable = new DataTable();
|
|
|
|
|
+ int startRow = 0;
|
|
|
|
|
+ FileStream fs;
|
|
|
|
|
+ IWorkbook workbook = null;
|
|
|
|
|
+ int cellCount = 0;
|
|
|
|
|
+ int rowCount = 0;
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
|
|
|
|
|
+ if (fileName.IndexOf(".xlsx") > 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ workbook = new XSSFWorkbook(fs);
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (fileName.IndexOf(".xls") > 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ workbook = new HSSFWorkbook(fs);
|
|
|
|
|
+ }
|
|
|
|
|
+ sheet = workbook.GetSheetAt(0);
|
|
|
|
|
+ if (sheet != null)
|
|
|
|
|
+ {
|
|
|
|
|
+ IRow firstRow = sheet.GetRow(0);
|
|
|
|
|
+ cellCount = firstRow.LastCellNum;
|
|
|
|
|
+ for (int i = firstRow.FirstCellNum; i < cellCount; ++i)
|
|
|
|
|
+ {
|
|
|
|
|
+ DataColumn column = new DataColumn(firstRow.GetCell(i).StringCellValue);
|
|
|
|
|
+ datatable.Columns.Add(column);
|
|
|
|
|
+ }
|
|
|
|
|
+ startRow = sheet.FirstRowNum + 1;
|
|
|
|
|
+ rowCount = sheet.LastRowNum;
|
|
|
|
|
+ for (int i = startRow; i <= rowCount; ++i)
|
|
|
|
|
+ {
|
|
|
|
|
+ IRow row = sheet.GetRow(i);
|
|
|
|
|
+ if (row == null)
|
|
|
|
|
+ {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ DataRow dataRow = datatable.NewRow();
|
|
|
|
|
+ for (int y = 0; y <= cellCount; y++)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (row.GetCell(y) != null && row.GetCell(y).ToString() != String.Empty && row.GetCell(y).ToString() != "" && row.GetCell(y).ToString().Trim() != "")
|
|
|
|
|
+ {
|
|
|
|
|
+ dataRow[y] = row.GetCell(y).ToString();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ datatable.Rows.Add(dataRow);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return datatable;
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (Exception ex)
|
|
|
|
|
+ {
|
|
|
|
|
+ Console.WriteLine("Exception: " + ex.Message);
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ #endregion
|
|
|
}
|
|
}
|