1。首先写一个Excel表格,第一行数据库类型(varchar、date、decimal)。第二行数据库类型长度(100、12,4、时间日期为空)
2。html 加按钮

  1. {
  2. type: "button",
  3. text: "报价信息导入",
  4. click: function () {
  5. GA.clearScreenMessage();
  6. //terpQuoteMnt=>表名, GA.currentUser.CompanyId=>公司id ,uploadPopupQuoteDiv =>div
  7. var data = ["terpQuoteMnt", GA.currentUser.CompanyId, "uploadPopupQuoteDiv"];
  8. GA.current.window = $("#uploadPopupQuoteDiv").kendoWindow({
  9. // modal: true,
  10. content: { url: "/Common/BaseDataUploadQuery", data: { name: JSON.stringify(data) }},
  11. iframe: false,
  12. width: 900,
  13. height: 200,
  14. title: "报价信息文件上传",
  15. }).data("kendoWindow");
  16. GA.current.window.center().open();
  17. }
  18. },

3。(下载模板)设置Excel中模板下拉框,为可新增下拉框或不可新增下拉框,实现对用户的一些输入限制

  1. using DC.BE.Business.ERP;
  2. using DC.BE.Business.ERP.ProductsMange;
  3. using DC.BE.Business.SYS;
  4. using DC.BE.Entity.Security;
  5. using NPOI.SS.UserModel;
  6. using NPOI.SS.Util;
  7. using NPOI.XSSF.UserModel;
  8. using System;
  9. using System.Collections.Generic;
  10. //using DC.BE.Entity.SYS;
  11. using System.Data.Entity;
  12. using System.IO;
  13. using System.Linq;
  14. using System.Web.Mvc;
  15. using DC.BE.Business.ERP.Purchases;
  16.  
  17. ///Install-Package NPOI
  18. namespace DC.Website.MVC5.Controllers.SYS.Base
  19. {
  20. public class BaseDataExportController : Controller
  21. {
  22. #region
  23. private readonly ITsysCompCodeBusiness _tsysCompCodeBusiness;
  24. private readonly IterpProductBusiness _terpProductBusiness;
  25. private readonly IterpPersonInfoBusiness _terpPersonInfoBusiness;
  26. private readonly IterpPartBusiness _terpPartBusiness;
  27. private readonly ITsysManagementBusiness _tsysManagementBusiness;
  28. private readonly DcContext _dcContext;
  29. private readonly ItsysCompRoleBusiness _tsysCompRoleBusiness;
  30. private readonly ITsysUserBusiness _tsysUserBusiness;
  31. private readonly ITerpQuotedPriceTemplateBusiness _terpQuotedPriceTemplateBusiness;
  32. public BaseDataExportController(ITsysCompCodeBusiness tsysCompCodeBusiness, IterpProductBusiness terpProductBusiness,
  33. IterpPersonInfoBusiness terpPersonInfoBusiness, IterpPartBusiness terpPartBusiness, ITsysManagementBusiness tsysManagementBusiness,
  34. ITerpQuotedPriceTemplateBusiness terpQuotedPriceTemplateBusiness,
  35. DcContext dcContext, ItsysCompRoleBusiness tsysCompRoleBusiness,ITsysUserBusiness tsysUserBusiness)
  36. {
  37. _tsysCompCodeBusiness = tsysCompCodeBusiness;
  38. _terpProductBusiness = terpProductBusiness;
  39. _terpPersonInfoBusiness = terpPersonInfoBusiness;
  40. _terpPartBusiness = terpPartBusiness;
  41. _tsysManagementBusiness = tsysManagementBusiness;
  42. _dcContext = dcContext;
  43. _tsysCompRoleBusiness = tsysCompRoleBusiness;
  44. _tsysUserBusiness = tsysUserBusiness;
  45. _terpQuotedPriceTemplateBusiness = terpQuotedPriceTemplateBusiness;
  46. }
  47. #endregion
  48.  
  49. private const string TemplatePath = @"~\Template\Excel\";
  50. private const int MaxRowIndex = ;
  51. //[AllowAnonymous]
  52. public ActionResult ExportTemplate(string template)
  53. {
  54. switch (template)
  55. {
  56. case "terpPersonInfo":
  57. return ExportTerpPersonInfo();
  58. case "terpPartInfo":
  59. return ExportTerpPartInfo();
  60. case "terpProductInfo":
  61. return ExportTerpProductBase();
  62. case "terpMaterialBase":
  63. return ExportTerpMaterialBase();
  64. case "tsysCompOrg":
  65. return ExportTsysCompOrg();
  66. case "tsysCompRole":
  67. return ExportTsysCompRole();
  68. case "tsysUser":
  69. return ExportTsysUser();
  70. case "tsysUserRole":
  71. return ExportTsysUserRole();
  72. case "TerpWorkHourCostTypeId":
  73. return ExportTerpWorkHourCostTypeId();
  74. case "terpSupplierInfo":
  75. return ExportTerpSupplierInfo();
  76. case "terpSupplyBase":
  77. return ExportTerpSupplyBase();
  78. case "tsysStoreInfo":
  79. return ExportTsysStoreInfo();
  80. case "terpTechUseMaterialDF":
  81. return ExportTerpTechUseMaterialDF();
  82. case "terpProductDesignBom":
  83. return ExportTerpDesignBom();
  84. case "terpPartRelation":
  85. return ExportTerpDesignBomPartRelation();
  86. case "terpPartTotolStoreInfo":
  87. return ExportTerpPartTotolStoreInfo();
  88. case "tsysStorePartition":
  89. return ExportTsysStorePartition();
  90. case "tsysStoreLocation":
  91. return ExportTsysStoreLocation();
  92. case "tcrmCustomerInfo":
  93. return ExportTcrmCustomerInfo();
  94. case "terpPartInStoreInfo":
  95. return ExportTerpPartInStoreInfo();
  96. case "tsasAgentRegister":
  97. return ExportTsasAgentRegister();
  98. case "tsasRegCompServiceNote":
  99. return ExportTsasRegCompServiceNote();
  100. case "terpQuoteMnt":
  101. return ExportTerpQuoteMnt();
  102. default:
  103. return ExportTerpPersonInfo();
  104. }
  105.  
  106. }
  107.  
  108. #region 由数据源生成下拉菜单
  109. /// <summary>
  110. /// 由数据源生成下拉菜单
  111. /// </summary>
  112. /// <param name="workbook">XSSFWorkbook</param>
  113. /// <param name="category">category</param>
  114. /// <param name="columnName">列标题</param>
  115. /// <param name="colString">下拉菜单列坐标</param>
  116. /// <param name="sheetIndex">下拉菜单sheet页索引</param>
  117. /// <param name="firstRowIndex">下拉菜单起始行索引</param>
  118. /// <param name="lastRowIndex">下拉菜单结束行索引</param>
  119. private void GenerateDropdownListRow(XSSFWorkbook workbook, string category, string columnName, string colString,
  120. int sheetIndex = , int firstRowIndex = , int lastRowIndex = MaxRowIndex)
  121. {
  122. var sheet = workbook.GetSheetAt(sheetIndex);
  123. XSSFDataValidationHelper dvHelper = new XSSFDataValidationHelper((XSSFSheet)sheet);
  124. //下拉菜单数据源
  125. string[] data = _tsysCompCodeBusiness.GetCodesByCategoryCodeCompanyId(category).Select(x => x.Item_Name).OrderBy(x => x).ToArray();
  126.  
  127. if (data.Length == )
  128. {
  129. data = new string[] { "" };
  130. }
  131.  
  132. int validationLength = string.Join(",", data).Length;
  133. /*
  134. There are limits to the number of items that will show in a data validation drop down list:
  135. The list can show up to show 32,767 items from a list on the worksheet.
  136. If you type the items into the data validation dialog box (a delimited list), the limit is 256 characters, including the separators.
  137. */
  138. if (validationLength >= || data.Length > )
  139. {
  140. ISheet hidden = null;
  141. if (workbook.GetSheet("hidden") == null)
  142. {
  143. hidden = workbook.CreateSheet("hidden");
  144. }
  145. int hiddenSheetIndex = workbook.GetSheetIndex(workbook.GetSheet("hidden"));
  146. GenerateCascadingDropdownListRow(workbook, data, columnName, colString, colString, ddlSheetIndex: sheetIndex, dsSheetIndex: hiddenSheetIndex);
  147. workbook.SetSheetHidden(hiddenSheetIndex, true);
  148. return;
  149. }
  150.  
  151. XSSFDataValidationConstraint dvConstraint = (XSSFDataValidationConstraint)
  152. dvHelper.CreateExplicitListConstraint(data);
  153. //根据列坐标获取索引
  154. int colIndex = CellReference.ConvertColStringToIndex((colString ?? "").ToUpper());
  155. //下拉菜单约束范围
  156. CellRangeAddressList addressList = new CellRangeAddressList(firstRowIndex, lastRowIndex, colIndex, colIndex);
  157. XSSFDataValidation validation = (XSSFDataValidation)dvHelper.CreateValidation(dvConstraint, addressList);
  158. validation.ShowErrorBox = true;
  159. //string colName = sheet.GetRow(firstRowIndex - 1).GetCell(colIndex).StringCellValue;
  160. validation.CreateErrorBox("错误", columnName + "错误");//不符合约束时提示
  161. sheet.AddValidationData(validation);
  162. }
  163.  
  164. private void GenerateDropdownListRow(XSSFWorkbook workbook, string[] data, string columnName, string colString,
  165. int sheetIndex = , int firstRowIndex = , int lastRowIndex = MaxRowIndex)
  166. {
  167. var sheet = workbook.GetSheetAt(sheetIndex);
  168. XSSFDataValidationHelper dvHelper = new XSSFDataValidationHelper((XSSFSheet)sheet);
  169. //下拉菜单数据源
  170. //string[] data = _tsysCompCodeBusiness.GetCodesByCategoryCode(category).Select(x => x.Item_Name).ToArray();
  171. if (data.Length == )
  172. {
  173. data = new string[] { "" };
  174. }
  175.  
  176. int validationLength = string.Join(",", data).Length;
  177. /*
  178. There are limits to the number of items that will show in a data validation drop down list:
  179. The list can show up to show 32,767 items from a list on the worksheet.
  180. If you type the items into the data validation dialog box (a delimited list), the limit is 256 characters, including the separators.
  181. */
  182. if (validationLength >= || data.Length > )
  183. {
  184. ISheet hidden = null;
  185. if (workbook.GetSheet("hidden") == null)
  186. {
  187. hidden = workbook.CreateSheet("hidden");
  188. }
  189. int hiddenSheetIndex = workbook.GetSheetIndex(workbook.GetSheet("hidden"));
  190. GenerateCascadingDropdownListRow(workbook, data, columnName, colString, colString, ddlSheetIndex: sheetIndex, dsSheetIndex: hiddenSheetIndex);
  191. workbook.SetSheetHidden(hiddenSheetIndex, true);
  192. return;
  193. }
  194.  
  195. XSSFDataValidationConstraint dvConstraint = (XSSFDataValidationConstraint)
  196. dvHelper.CreateExplicitListConstraint(data);
  197. //根据列坐标获取索引
  198. int colIndex = CellReference.ConvertColStringToIndex((colString ?? "").ToUpper());
  199. //下拉菜单约束范围
  200. CellRangeAddressList addressList = new CellRangeAddressList(firstRowIndex, lastRowIndex, colIndex, colIndex);
  201. XSSFDataValidation validation = (XSSFDataValidation)dvHelper.CreateValidation(dvConstraint, addressList);
  202. validation.ShowErrorBox = true;
  203. //string colName = sheet.GetRow(firstRowIndex - 1).GetCell(colIndex).StringCellValue;
  204. validation.CreateErrorBox("错误", columnName + "错误");//不符合约束时提示
  205. sheet.AddValidationData(validation);
  206. }
  207. #endregion
  208.  
  209. #region 数据有效性验证 列元素不可重复
  210. /// <summary>
  211. /// 数据有效性验证 列元素不可重复
  212. /// </summary>
  213. /// <param name="workbook"></param>
  214. /// <param name="columnName">列标题</param>
  215. /// <param name="colString">列坐标</param>
  216. /// <param name="sheetIndex">下拉菜单sheet页索引</param>
  217. /// <param name="firstRowIndex">下拉菜单起始行索引</param>
  218. /// <param name="lastRowIndex">下拉菜单结束行索引</param>
  219. private void CheckListRow(XSSFWorkbook workbook, string columnName, string colString,
  220. int sheetIndex = , int firstRowIndex = , int lastRowIndex = MaxRowIndex)
  221. {
  222. var sheet = workbook.GetSheetAt(sheetIndex);//获取Excel sheet页面
  223. XSSFDataValidationHelper dvHelper = new XSSFDataValidationHelper((XSSFSheet)sheet);
  224. //根据列坐标获取索引
  225. int colIndex = CellReference.ConvertColStringToIndex((colString ?? "").ToUpper());//根据列坐标获取索引
  226. CellRangeAddressList regions = new CellRangeAddressList(firstRowIndex, , colIndex, colIndex); //选定一个区域 (起始行序号,终止行序号,起始列序号,终止列序号)
  227. XSSFDataValidationConstraint dvConstraint = (XSSFDataValidationConstraint)
  228. dvHelper.CreateCustomConstraint(string.Format("COUNTIF(${0}:${0},{0}4)<2", colString));//数据有效性设置 自定义
  229. //COUNTIF($A:$A,A4)<2
  230. XSSFDataValidation validation = (XSSFDataValidation)dvHelper.CreateValidation(dvConstraint, regions);//创建验证
  231. validation.ShowErrorBox = true;//显示出错警告
  232. validation.CreateErrorBox("错误", columnName + "元素重复");//出错警告设置
  233. sheet.AddValidationData(validation);//添加验证
  234.  
  235. }
  236.  
  237. #endregion
  238.  
  239. #region 由数据源及数据源sheet页生成下拉菜单
  240. /// <summary>
  241. /// 由数据源及数据源sheet页生成下拉菜单
  242. /// </summary>
  243. /// <param name="workbook">XSSFWorkbook</param>
  244. /// <param name="category">category</param>
  245. /// <param name="columnName">列标题</param>
  246. /// <param name="ddlColString">下拉菜单列坐标</param>
  247. /// <param name="dsColString">数据源列坐标</param>
  248. /// <param name="ddlSheetIndex">下拉菜单sheet页索引</param>
  249. /// <param name="dsSheetIndex">数据源sheet页索引</param>
  250. /// <param name="ddlFirstRowIndex">下拉菜单起始行索引</param>
  251. /// <param name="ddlLastRowIndex">下拉菜单结束行索引</param>
  252. /// <param name="dsFirstRowIndex">数据源起始行索引</param>
  253. /// <param name="dsLastRowIndex">数据源结束行索引</param>
  254. private void GenerateCascadingDropdownListRow(XSSFWorkbook workbook, string category, string columnName, string ddlColString,
  255. string dsColString, int ddlSheetIndex = , int dsSheetIndex = , int ddlFirstRowIndex = , int ddlLastRowIndex = MaxRowIndex,
  256. int dsFirstRowIndex = , int dsLastRowIndex = MaxRowIndex)
  257. {
  258. ISheet ddlSheet = workbook.GetSheetAt(ddlSheetIndex);
  259. ISheet dsSheet = workbook.GetSheetAt(dsSheetIndex);
  260. XSSFDataValidationHelper dvHelper = new XSSFDataValidationHelper((XSSFSheet)ddlSheet);
  261. int ddlColIndex = CellReference.ConvertColStringToIndex((ddlColString ?? "").ToUpper());
  262. int dsColIndex = CellReference.ConvertColStringToIndex((dsColString ?? "").ToUpper());
  263.  
  264. ICellStyle unblockStyle = workbook.CreateCellStyle();
  265. unblockStyle.IsLocked = false;
  266. ((XSSFSheet)dsSheet).GetColumnHelper().SetColDefaultStyle(dsColIndex, unblockStyle);
  267.  
  268. //下拉菜单数据源
  269. string[] data = _tsysCompCodeBusiness.GetCodesByCategoryCode(category).Select(x => x.Item_Name).OrderBy(x => x).ToArray();
  270. IRow titleRow = dsSheet.GetRow() ?? dsSheet.CreateRow();
  271. ICell titleCell = titleRow.GetCell(dsColIndex) ?? titleRow.CreateCell(dsColIndex);
  272. titleCell.SetCellValue(columnName ?? "");
  273.  
  274. ICellStyle titleStyle = workbook.CreateCellStyle();
  275. if (ddlSheet.GetRow(ddlFirstRowIndex - ) != null)
  276. {
  277. ICellStyle style = ddlSheet.GetRow(ddlFirstRowIndex - ).GetCell(ddlColIndex).CellStyle;
  278. titleStyle.CloneStyleFrom(style);
  279. }
  280. titleCell.CellStyle = titleStyle;
  281.  
  282. titleCell.CellStyle.IsLocked = true;
  283. //下拉菜单数据源
  284. if (data != null && data.Length > )
  285. {
  286. for (int i = ; i < data.Length; i++)
  287. {
  288. IRow row = dsSheet.GetRow(dsFirstRowIndex + i) ?? dsSheet.CreateRow(dsFirstRowIndex + i);
  289. ICell cell = row.GetCell(dsColIndex) ?? row.CreateCell(dsColIndex);
  290. cell.SetCellValue(data[i]);
  291. cell.CellStyle.IsLocked = true;
  292. }
  293. }
  294.  
  295. dsSheet.AutoSizeColumn(dsColIndex);
  296. dsSheet.ProtectSheet("");
  297. IName range = workbook.CreateName();
  298. //range.RefersToFormula = string.Format("{0}!${1}${2}:${1}${3}", dsSheet.SheetName, (dsColString ?? "").ToUpper(), dsFirstRowIndex + 1, dsLastRowIndex);
  299. range.RefersToFormula = string.Format("{0}!${1}${2}:INDEX({0}!${1}${2}:${1}${3},SUMPRODUCT(--({0}!${1}${2}:${1}${3}<>\"\")))", dsSheet.SheetName, (dsColString ?? "").ToUpper(), dsFirstRowIndex + , dsLastRowIndex);
  300. //range.RefersToFormula = string.Format("OFFSET(INDIRECT(\"{0}!${1}${2}\"),0,0,COUNTA({0}!${1}:${1}),1)", dsSheet.SheetName, (dsColString ?? "").ToUpper(), dsFirstRowIndex + 1, dsLastRowIndex);
  301. //string colName = ddlSheet.GetRow(ddlFirstRowIndex - 1).GetCell(ddlColIndex).StringCellValue;
  302. range.NameName = columnName;
  303.  
  304. //下拉菜单约束范围
  305. CellRangeAddressList addressList = new CellRangeAddressList(ddlFirstRowIndex, ddlLastRowIndex, ddlColIndex, ddlColIndex);
  306. XSSFDataValidation validation = (XSSFDataValidation)dvHelper.CreateValidation(dvHelper.CreateFormulaListConstraint(columnName), addressList);
  307.  
  308. validation.ShowErrorBox = true;
  309. validation.CreateErrorBox("错误", columnName + "错误");
  310. ddlSheet.AddValidationData(validation);
  311. }
  312.  
  313. private void GenerateCascadingDropdownListRow(XSSFWorkbook workbook, string[] data, string columnName, string ddlColString,
  314. string dsColString, int ddlSheetIndex = , int dsSheetIndex = , int ddlFirstRowIndex = , int ddlLastRowIndex = MaxRowIndex,
  315. int dsFirstRowIndex = , int dsLastRowIndex = MaxRowIndex)
  316. {
  317. ISheet ddlSheet = workbook.GetSheetAt(ddlSheetIndex);
  318. ISheet dsSheet = workbook.GetSheetAt(dsSheetIndex);
  319. XSSFDataValidationHelper dvHelper = new XSSFDataValidationHelper((XSSFSheet)ddlSheet);
  320. int ddlColIndex = CellReference.ConvertColStringToIndex((ddlColString ?? "").ToUpper());
  321. int dsColIndex = CellReference.ConvertColStringToIndex((dsColString ?? "").ToUpper());
  322.  
  323. ICellStyle unblockStyle = workbook.CreateCellStyle();
  324. unblockStyle.IsLocked = false;
  325. ((XSSFSheet)dsSheet).GetColumnHelper().SetColDefaultStyle(dsColIndex, unblockStyle);
  326.  
  327. //下拉菜单数据源
  328. IRow titleRow = dsSheet.GetRow() ?? dsSheet.CreateRow();
  329. ICell titleCell = titleRow.GetCell(dsColIndex) ?? titleRow.CreateCell(dsColIndex);
  330. titleCell.SetCellValue(columnName ?? "");
  331.  
  332. ICellStyle titleStyle = workbook.CreateCellStyle();
  333. if (ddlSheet.GetRow(ddlFirstRowIndex - ) != null)
  334. {
  335. ICellStyle style = ddlSheet.GetRow(ddlFirstRowIndex - ).GetCell(ddlColIndex).CellStyle;
  336. titleStyle.CloneStyleFrom(style);
  337. }
  338. titleCell.CellStyle = titleStyle;
  339.  
  340. titleCell.CellStyle.IsLocked = true;
  341. //下拉菜单数据源
  342. if (data != null && data.Length > )
  343. {
  344. for (int i = ; i < data.Length; i++)
  345. {
  346. IRow row = dsSheet.GetRow(dsFirstRowIndex + i) ?? dsSheet.CreateRow(dsFirstRowIndex + i);
  347. ICell cell = row.GetCell(dsColIndex) ?? row.CreateCell(dsColIndex);
  348. cell.SetCellValue(data[i]);
  349. cell.CellStyle.IsLocked = true;
  350. }
  351. }
  352.  
  353. dsSheet.AutoSizeColumn(dsColIndex);
  354. dsSheet.ProtectSheet("");
  355. IName range = workbook.CreateName();
  356. range.RefersToFormula = string.Format("{0}!${1}${2}:INDEX({0}!${1}${2}:${1}${3},SUMPRODUCT(--({0}!${1}${2}:${1}${3}<>\"\")))", dsSheet.SheetName, (dsColString ?? "").ToUpper(), dsFirstRowIndex + , dsLastRowIndex);
  357. range.NameName = columnName;
  358.  
  359. //下拉菜单约束范围
  360. CellRangeAddressList addressList = new CellRangeAddressList(ddlFirstRowIndex, ddlLastRowIndex, ddlColIndex, ddlColIndex);
  361. XSSFDataValidation validation = (XSSFDataValidation)dvHelper.CreateValidation(dvHelper.CreateFormulaListConstraint(columnName), addressList);
  362.  
  363. validation.ShowErrorBox = true;
  364. validation.CreateErrorBox("错误", columnName + "错误");
  365. ddlSheet.AddValidationData(validation);
  366. }
  367. #endregion
  368.  
  369. #region terpPersonInfo
  370. public ActionResult ExportTerpPersonInfo()
  371. {
  372. string templateFile = "terpPersonInfo.xlsx";
  373. try
  374. {
  375. using (FileStream fs = new FileStream(Server.MapPath(string.Format("{0}{1}", TemplatePath, templateFile)), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
  376. {
  377. XSSFWorkbook templateWorkbook = new XSSFWorkbook(fs);
  378. int dsSheetIndex = ;
  379. int ddlSheetIndex = ;
  380. //性别
  381. GenerateDropdownListRow(templateWorkbook, "", "性别", "D", ddlSheetIndex);
  382. //政治面貌
  383. GenerateCascadingDropdownListRow(templateWorkbook, "", "政治面貌", "H", "A", ddlSheetIndex, dsSheetIndex);
  384. //婚姻状况
  385. GenerateDropdownListRow(templateWorkbook, "", "婚姻状况", "F", ddlSheetIndex);
  386. //民族
  387. GenerateCascadingDropdownListRow(templateWorkbook, "", "民族", "I", "B", ddlSheetIndex, dsSheetIndex);
  388. //在职状态
  389. GenerateCascadingDropdownListRow(templateWorkbook, "", "在职状态", "S", "C", ddlSheetIndex, dsSheetIndex);
  390. //最高职称
  391. GenerateCascadingDropdownListRow(templateWorkbook, "", "最高职称", "Y", "D", ddlSheetIndex, dsSheetIndex);
  392. //员工类型
  393. GenerateDropdownListRow(templateWorkbook, "", "员工类型", "T", ddlSheetIndex);
  394. //开户银行
  395. GenerateCascadingDropdownListRow(templateWorkbook, "", "开户银行", "Z", "E", ddlSheetIndex, dsSheetIndex);
  396. //离职类型
  397. GenerateCascadingDropdownListRow(templateWorkbook, "", "离职类型", "AC", "F", ddlSheetIndex, dsSheetIndex);
  398. //户口性质
  399. GenerateCascadingDropdownListRow(templateWorkbook, "", "户口性质", "AG", "G", ddlSheetIndex, dsSheetIndex);
  400. //所属公司
  401. GenerateCascadingDropdownListRow(templateWorkbook, "", "所属公司", "AI", "H", ddlSheetIndex, dsSheetIndex);
  402.  
  403. CheckListRow(templateWorkbook, "员工编号", "A");
  404. using (MemoryStream ms = new MemoryStream())
  405. {
  406. templateWorkbook.Write(ms);
  407. return File(ms.ToArray(), "application/vnd.ms-excel", templateFile);
  408. }
  409. }
  410. }
  411. catch (Exception ex)
  412. {
  413. return View(ex.Message);
  414. }
  415. }
  416. #endregion
  417.  
  418. #region TerpPartInfo
  419. private ActionResult ExportTerpPartInfo()
  420. {
  421. string templateFile = "terpPartInfo.xlsx";
  422.  
  423. try
  424. {
  425. using (FileStream fs = new FileStream(Server.MapPath(string.Format("{0}{1}", TemplatePath, templateFile)), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
  426. {
  427. XSSFWorkbook templateWorkbook = new XSSFWorkbook(fs);
  428. //单位
  429. GenerateCascadingDropdownListRow(templateWorkbook, "", "单位", "C", "A", , );
  430. //生产性质
  431. GenerateDropdownListRow(templateWorkbook, "", "生产性质", "G", );
  432. //图纸纸张大小
  433. GenerateCascadingDropdownListRow(templateWorkbook, "", "图纸大小", "R", "B", , );
  434. //生产难度
  435. GenerateCascadingDropdownListRow(templateWorkbook, "", "生产难度", "J", "C", , );
  436. //工时分类
  437. string[] data = _terpProductBusiness.GetWorkHourType().OrderBy(x => x.WorkHourCostTypeName).Select(x => x.WorkHourCostTypeName).ToArray();
  438. GenerateDropdownListRow(templateWorkbook, data, "工时分类", "P", );
  439. //所属仓库
  440. string ObjStoreType = "";
  441. string[] StoreNameArray = _terpPartBusiness.GetStoreName(ObjStoreType).OrderBy(x => x.Store_Name).Select(x => x.Store_Name).ToArray();
  442. GenerateDropdownListRow(templateWorkbook, StoreNameArray, "所属仓库", "L", );
  443. //设计者
  444. string[] designArray = _terpPersonInfoBusiness.GetAllActive().Include(x => x.Org).OrderBy(x => x.EmployeeName).Select(x => x.EmployeeName).ToArray();
  445. GenerateDropdownListRow(templateWorkbook, designArray, "设计者", "X", );
  446. //审核者
  447. string[] verifyArray = _terpPersonInfoBusiness.GetAllActive().Include(x => x.Org).OrderBy(x => x.EmployeeName).Select(x => x.EmployeeName).ToArray();
  448. GenerateDropdownListRow(templateWorkbook, verifyArray, "审核者", "Z", );
  449.  
  450. CheckListRow(templateWorkbook, "编码", "A");
  451. using (MemoryStream ms = new MemoryStream())
  452. {
  453. templateWorkbook.Write(ms);
  454. return File(ms.ToArray(), "application/vnd.ms-excel", templateFile);
  455. }
  456. }
  457. }
  458. catch (Exception ex)
  459. {
  460. return View(ex.Message);
  461. }
  462. }
  463. #endregion
  464.  
  465. #region TerpProductBase 更名terpProductInfo
  466. private ActionResult ExportTerpProductBase()
  467. {
  468. // string templateFile = "terpProductBase.xlsx";
  469. string templateFile = "terpProductInfo.xlsx";
  470. try
  471. {
  472. using (FileStream fs = new FileStream(Server.MapPath(string.Format("{0}{1}", TemplatePath, templateFile)), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
  473. {
  474. XSSFWorkbook templateWorkbook = new XSSFWorkbook(fs);
  475. //单位
  476. GenerateCascadingDropdownListRow(templateWorkbook, "", "单位", "C", "A", , );
  477. //生产难度
  478. GenerateCascadingDropdownListRow(templateWorkbook, "", "生产难度", "J", "B", , );
  479. //图纸大小
  480. GenerateCascadingDropdownListRow(templateWorkbook, "", "图纸大小", "Q", "C", , );
  481. //产品分类
  482. GenerateCascadingDropdownListRow(templateWorkbook, "", "产品分类", "D", "D", , );
  483. //工时分类
  484. string[] data = _terpProductBusiness.GetWorkHourType().OrderBy(x => x.WorkHourCostTypeName).Select(x => x.WorkHourCostTypeName).ToArray();
  485. GenerateDropdownListRow(templateWorkbook, data, "工时分类", "O", );
  486. //所属仓库
  487. string ObjStoreType = "";
  488. string[] StoreNameArray = _terpPartBusiness.GetStoreName(ObjStoreType).OrderBy(x => x.Store_Name).Select(x => x.Store_Name).ToArray();
  489. GenerateDropdownListRow(templateWorkbook, StoreNameArray, "所属仓库", "L", );
  490. //设计者
  491. string[] designArray = _terpPersonInfoBusiness.GetAllActive().Include(x => x.Org).OrderBy(x => x.EmployeeName).Select(x => x.EmployeeName).ToArray();
  492. GenerateDropdownListRow(templateWorkbook, designArray, "设计者", "W", );
  493. //审核者
  494. string[] verifyArray = _terpPersonInfoBusiness.GetAllActive().Include(x => x.Org).OrderBy(x => x.EmployeeName).Select(x => x.EmployeeName).ToArray();
  495. GenerateDropdownListRow(templateWorkbook, verifyArray, "审核者", "Y", );
  496.  
  497. CheckListRow(templateWorkbook, "编码", "A");
  498. using (MemoryStream ms = new MemoryStream())
  499. {
  500. templateWorkbook.Write(ms);
  501. return File(ms.ToArray(), "application/vnd.ms-excel", templateFile);
  502. }
  503. }
  504. }
  505. catch (Exception ex)
  506. {
  507. return View(ex.Message);
  508. }
  509. }
  510. #endregion
  511.  
  512. #region TerpMaterialBase
  513. private ActionResult ExportTerpMaterialBase()
  514. {
  515. string templateFile = "terpMaterialBase.xlsx";
  516.  
  517. try
  518. {
  519. using (FileStream fs = new FileStream(Server.MapPath(string.Format("{0}{1}", TemplatePath, templateFile)), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
  520. {
  521. XSSFWorkbook templateWorkbook = new XSSFWorkbook(fs);
  522. //核算用单位
  523. GenerateCascadingDropdownListRow(templateWorkbook, "", "核算用单位", "E", "A", , );
  524. //非核算用单位
  525. GenerateCascadingDropdownListRow(templateWorkbook, "", "非核算用单位", "F", "B", , );
  526. //所属仓库
  527. string ObjStoreType = "";
  528. string[] StoreNameArray = _terpPartBusiness.GetStoreName(ObjStoreType).OrderBy(x => x.Store_Name).Select(x => x.Store_Name).ToArray();
  529. GenerateDropdownListRow(templateWorkbook, StoreNameArray, "仓库名称", "G", );
  530.  
  531. CheckListRow(templateWorkbook, "原材料编号", "A");
  532. using (MemoryStream ms = new MemoryStream())
  533. {
  534. templateWorkbook.Write(ms);
  535. return File(ms.ToArray(), "application/vnd.ms-excel", templateFile);
  536. }
  537. }
  538. }
  539. catch (Exception ex)
  540. {
  541. return View(ex.Message);
  542. }
  543. }
  544. #endregion
  545.  
  546. #region TsysCompOrg
  547. private ActionResult ExportTsysCompOrg()
  548. {
  549. string templateFile = "tsysCompOrg.xlsx";
  550.  
  551. try
  552. {
  553. using (FileStream fs = new FileStream(Server.MapPath(string.Format("{0}{1}", TemplatePath, templateFile)), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
  554. {
  555. XSSFWorkbook templateWorkbook = new XSSFWorkbook(fs);
  556. CheckListRow(templateWorkbook, "组织机构编码", "A");
  557. using (MemoryStream ms = new MemoryStream())
  558. {
  559. templateWorkbook.Write(ms);
  560. return File(ms.ToArray(), "application/vnd.ms-excel", templateFile);
  561. }
  562. }
  563. }
  564. catch (Exception ex)
  565. {
  566. return View(ex.Message);
  567. }
  568. }
  569. #endregion
  570.  
  571. #region TsysCompRole
  572. private ActionResult ExportTsysCompRole()
  573. {
  574. string templateFile = "tsysCompRole.xlsx";
  575.  
  576. try
  577. {
  578. using (FileStream fs = new FileStream(Server.MapPath(string.Format("{0}{1}", TemplatePath, templateFile)), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
  579. {
  580. XSSFWorkbook templateWorkbook = new XSSFWorkbook(fs);
  581.  
  582. GenerateDropdownListRow(templateWorkbook, "", "角色类型", "C", );
  583. CheckListRow(templateWorkbook, "角色编码", "A");
  584. using (MemoryStream ms = new MemoryStream())
  585. {
  586. templateWorkbook.Write(ms);
  587. return File(ms.ToArray(), "application/vnd.ms-excel", templateFile);
  588. }
  589. }
  590. }
  591. catch (Exception ex)
  592. {
  593. return View(ex.Message);
  594. }
  595. }
  596. #endregion
  597.  
  598. #region TerpSupplyBase 物品表
  599. private ActionResult ExportTerpSupplyBase()
  600. {
  601. string templateFile = "terpSupplyBase.xlsx";
  602.  
  603. try
  604. {
  605. using (FileStream fs = new FileStream(Server.MapPath(string.Format("{0}{1}", TemplatePath, templateFile)), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
  606. {
  607. XSSFWorkbook templateWorkbook = new XSSFWorkbook(fs);
  608.  
  609. GenerateCascadingDropdownListRow(templateWorkbook, "", "单位", "C", "A", , );
  610.  
  611. GenerateCascadingDropdownListRow(templateWorkbook, "", "物品用途分类", "I", "B", , );
  612.  
  613. GenerateDropdownListRow(templateWorkbook, "", "生产性质", "J", );
  614.  
  615. GenerateDropdownListRow(templateWorkbook, "", "借领分类", "K", );
  616.  
  617. GenerateDropdownListRow(templateWorkbook, "", "领用审批", "M", );
  618. //所属仓库
  619. string ObjStoreType = "";
  620. string[] StoreNameArray = _terpPartBusiness.GetStoreName(ObjStoreType).OrderBy(x => x.Store_Name).Select(x => x.Store_Name).ToArray();
  621. GenerateDropdownListRow(templateWorkbook, StoreNameArray, "仓库名称", "G", );
  622.  
  623. CheckListRow(templateWorkbook, "物品编号", "A");
  624. using (MemoryStream ms = new MemoryStream())
  625. {
  626. templateWorkbook.Write(ms);
  627. return File(ms.ToArray(), "application/vnd.ms-excel", templateFile);
  628. }
  629. }
  630. }
  631. catch (Exception ex)
  632. {
  633. return View(ex.Message);
  634. }
  635. }
  636. #endregion
  637.  
  638. #region TsysUser
  639. private ActionResult ExportTsysUser()
  640. {
  641. string templateFile = "tsysUser.xlsx";
  642.  
  643. try
  644. {
  645. using (FileStream fs = new FileStream(Server.MapPath(string.Format("{0}{1}", TemplatePath, templateFile)), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
  646. {
  647. XSSFWorkbook templateWorkbook = new XSSFWorkbook(fs);
  648.  
  649. int ddlSheetIndex = ;
  650.  
  651. GenerateDropdownListRow(templateWorkbook, "", "性别", "C", ddlSheetIndex);
  652. //系统角色
  653. string[] data = _tsysCompCodeBusiness.GetCodesByCategoryCodeCompanyId("").Where(x => x.Item_Code != "").Select(x => x.Item_Name).OrderBy(x => x).ToArray();
  654. GenerateDropdownListRow(templateWorkbook, data, "系统角色", "I", ddlSheetIndex);
  655. //TsysUserDropdownListRow(templateWorkbook, "087", "系统角色", "J", ddlSheetIndex);
  656.  
  657. //角色名
  658. string[] roles = _tsysCompRoleBusiness.GetAllRole().Select(x => x.Role_Name).OrderBy(x => x).ToArray();
  659. GenerateDropdownListRow(templateWorkbook, roles, "角色名称", "J", ddlSheetIndex);
  660.  
  661. CheckListRow(templateWorkbook, "员工号", "B");
  662. using (MemoryStream ms = new MemoryStream())
  663. {
  664. templateWorkbook.Write(ms);
  665. return File(ms.ToArray(), "application/vnd.ms-excel", templateFile);
  666. }
  667. }
  668. }
  669. catch (Exception ex)
  670. {
  671. return View(ex.Message);
  672. }
  673. }
  674. #endregion
  675.  
  676. #region TsysUserRole
  677. private ActionResult ExportTsysUserRole()
  678. {
  679. string templateFile = "tsysUserRole.xlsx";
  680.  
  681. try
  682. {
  683. using (FileStream fs = new FileStream(Server.MapPath(string.Format("{0}{1}", TemplatePath, templateFile)), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
  684. {
  685. XSSFWorkbook templateWorkbook = new XSSFWorkbook(fs);
  686.  
  687. using (MemoryStream ms = new MemoryStream())
  688. {
  689. templateWorkbook.Write(ms);
  690. return File(ms.ToArray(), "application/vnd.ms-excel", templateFile);
  691. }
  692. }
  693. }
  694. catch (Exception ex)
  695. {
  696. return View(ex.Message);
  697. }
  698. }
  699. #endregion
  700.  
  701. #region TerpWorkHourCostTypeId
  702. private ActionResult ExportTerpWorkHourCostTypeId()
  703. {
  704. string templateFile = "TerpWorkHourCostTypeId.xlsx";
  705.  
  706. try
  707. {
  708. using (FileStream fs = new FileStream(Server.MapPath(string.Format("{0}{1}", TemplatePath, templateFile)), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
  709. {
  710. XSSFWorkbook templateWorkbook = new XSSFWorkbook(fs);
  711. CheckListRow(templateWorkbook, "工时费分类编码", "A");
  712. using (MemoryStream ms = new MemoryStream())
  713. {
  714. templateWorkbook.Write(ms);
  715. return File(ms.ToArray(), "application/vnd.ms-excel", templateFile);
  716. }
  717. }
  718. }
  719. catch (Exception ex)
  720. {
  721. return View(ex.Message);
  722. }
  723.  
  724. }
  725. #endregion
  726.  
  727. #region TerpTechUseMaterialDF
  728. private ActionResult ExportTerpTechUseMaterialDF()
  729. {
  730. string templateFile = "terpTechUseMaterialDF.xlsx";
  731.  
  732. try
  733. {
  734. using (FileStream fs = new FileStream(Server.MapPath(string.Format("{0}{1}", TemplatePath, templateFile)), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
  735. {
  736. XSSFWorkbook templateWorkbook = new XSSFWorkbook(fs);
  737.  
  738. using (MemoryStream ms = new MemoryStream())
  739. {
  740. templateWorkbook.Write(ms);
  741. return File(ms.ToArray(), "application/vnd.ms-excel", templateFile);
  742. }
  743. }
  744. }
  745. catch (Exception ex)
  746. {
  747. return View(ex.Message);
  748. }
  749. }
  750.  
  751. #endregion
  752.  
  753. #region TerpSupplierInfo
  754. private ActionResult ExportTerpSupplierInfo()
  755. {
  756. string templateFile = "terpSupplierInfo.xlsx";
  757.  
  758. try
  759. {
  760. using (FileStream fs = new FileStream(Server.MapPath(string.Format("{0}{1}", TemplatePath, templateFile)), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
  761. {
  762. XSSFWorkbook templateWorkbook = new XSSFWorkbook(fs);
  763.  
  764. //公司性质
  765. GenerateCascadingDropdownListRow(templateWorkbook, "", "公司性质", "D", "A", , );
  766. //行业类别
  767. GenerateCascadingDropdownListRow(templateWorkbook, "", "行业类别", "E", "B", , );
  768. //供应商分类
  769. GenerateDropdownListRow(templateWorkbook, "", "供应商分类", "G", );
  770. //供应商分级
  771. GenerateCascadingDropdownListRow(templateWorkbook, "", "供应商分级", "J", "C", , );
  772.  
  773. CheckListRow(templateWorkbook, "供应商编码", "A");
  774. using (MemoryStream ms = new MemoryStream())
  775. {
  776. templateWorkbook.Write(ms);
  777. return File(ms.ToArray(), "application/vnd.ms-excel", templateFile);
  778. }
  779. }
  780. }
  781. catch (Exception ex)
  782. {
  783. return View(ex.Message);
  784. }
  785. }
  786. #endregion
  787.  
  788. #region TerpDesignBom更名terpProductDesignBom
  789. private ActionResult ExportTerpDesignBom()
  790. {
  791. // string templateFile = "terpDesignBom.xlsx";
  792. string templateFile = "terpProductDesignBom.xlsx";
  793. try
  794. {
  795. //using (FileStream fs = new FileStream(Server.MapPath(string.Format("{0}{1}", TemplatePath, templateFile)), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
  796. //{
  797. // XSSFWorkbook templateWorkbook = new XSSFWorkbook(fs);
  798.  
  799. // using (MemoryStream ms = new MemoryStream())
  800. // {
  801. // templateWorkbook.Write(ms);
  802. // return File(ms.ToArray(), "application/vnd.ms-excel", templateFile);
  803. // }
  804. //}
  805. return File(string.Format("{0}{1}", TemplatePath, templateFile), "application/vnd.ms-excel", templateFile);
  806. }
  807. catch (Exception ex)
  808. {
  809. return View(ex.Message);
  810. }
  811. }
  812. #endregion
  813.  
  814. #region TerpDesignBomPartRelation 更名terpPartRelation
  815.  
  816. private ActionResult ExportTerpDesignBomPartRelation()
  817. {
  818. //string templateFile = "terpDesignBomPartRelation.xlsx";
  819. string templateFile = "terpPartRelation.xlsx";
  820.  
  821. try
  822. {
  823. //using (FileStream fs = new FileStream(Server.MapPath(string.Format("{0}{1}", TemplatePath, templateFile)), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
  824. //{
  825. // XSSFWorkbook templateWorkbook = new XSSFWorkbook(fs);
  826.  
  827. // using (MemoryStream ms = new MemoryStream())
  828. // {
  829. // templateWorkbook.Write(ms);
  830. // return File(ms.ToArray(), "application/vnd.ms-excel", templateFile);
  831. // }
  832. //}
  833. return File(string.Format("{0}{1}", TemplatePath, templateFile), "application/vnd.ms-excel", templateFile);
  834. }
  835. catch (Exception ex)
  836. {
  837. return View(ex.Message);
  838. }
  839. }
  840. #endregion
  841.  
  842. #region tsysStoreInfo 仓库表
  843. private ActionResult ExportTsysStoreInfo()
  844. {
  845. string templateFile = "tsysStoreInfo.xlsx";
  846.  
  847. try
  848. {
  849. using (FileStream fs = new FileStream(Server.MapPath(string.Format("{0}{1}", TemplatePath, templateFile)), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
  850. {
  851. XSSFWorkbook templateWorkbook = new XSSFWorkbook(fs);
  852.  
  853. GenerateDropdownListRow(templateWorkbook, "", "仓库类型", "C", );
  854.  
  855. CheckListRow(templateWorkbook, "仓库编码", "A");
  856. CheckListRow(templateWorkbook, "仓库名称", "B");
  857. using (MemoryStream ms = new MemoryStream())
  858. {
  859. templateWorkbook.Write(ms);
  860. return File(ms.ToArray(), "application/vnd.ms-excel", templateFile);
  861. }
  862. }
  863. }
  864. catch (Exception ex)
  865. {
  866. return View(ex.Message);
  867. }
  868. }
  869. #endregion
  870.  
  871. #region tsysStorePartition 仓库库位划分表
  872. private ActionResult ExportTsysStorePartition()
  873. {
  874. string templateFile = "tsysStorePartition.xlsx";
  875.  
  876. try
  877. {
  878. //using (FileStream fs = new FileStream(Server.MapPath(string.Format("{0}{1}", TemplatePath, templateFile)), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
  879. //{
  880. // XSSFWorkbook templateWorkbook = new XSSFWorkbook(fs);
  881. // using (MemoryStream ms = new MemoryStream())
  882. // {
  883. // templateWorkbook.Write(ms);
  884. // return File(ms.ToArray(), "application/vnd.ms-excel", templateFile);
  885. // }
  886. //}
  887. return File(string.Format("{0}{1}", TemplatePath, templateFile), "application/vnd.ms-excel", templateFile);
  888. }
  889. catch (Exception ex)
  890. {
  891. return View(ex.Message);
  892. }
  893. }
  894. #endregion
  895.  
  896. #region tsysStoreLocation 仓库库位管理
  897. private ActionResult ExportTsysStoreLocation()
  898. {
  899. string templateFile = "tsysStoreLocation.xlsx";
  900.  
  901. try
  902. {
  903. using (FileStream fs = new FileStream(Server.MapPath(string.Format("{0}{1}", TemplatePath, templateFile)), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
  904. {
  905. XSSFWorkbook templateWorkbook = new XSSFWorkbook(fs);
  906. GenerateDropdownListRow(templateWorkbook, "", "库位状态", "D", );
  907. using (MemoryStream ms = new MemoryStream())
  908. {
  909. templateWorkbook.Write(ms);
  910. return File(ms.ToArray(), "application/vnd.ms-excel", templateFile);
  911. }
  912. }
  913. }
  914. catch (Exception ex)
  915. {
  916. return View(ex.Message);
  917. }
  918. }
  919. #endregion
  920.  
  921. #region tcrmCustomerInfo 客户信息表
  922. private ActionResult ExportTcrmCustomerInfo()
  923. {
  924. string templateFile = "tcrmCustomerInfo.xlsx";
  925.  
  926. try
  927. {
  928. using (FileStream fs = new FileStream(Server.MapPath(string.Format("{0}{1}", TemplatePath, templateFile)), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
  929. {
  930. XSSFWorkbook templateWorkbook = new XSSFWorkbook(fs);
  931. GenerateCascadingDropdownListRow(templateWorkbook, "", "公司性质", "E", "A", , );
  932. GenerateCascadingDropdownListRow(templateWorkbook, "", "行业类别", "G", "B", , );
  933. GenerateCascadingDropdownListRow(templateWorkbook, "", "发货方式", "O", "C", , );
  934. GenerateCascadingDropdownListRow(templateWorkbook, "", "成交方式", "R", "D", , );
  935. GenerateCascadingDropdownListRow(templateWorkbook, "", "结算方式", "T", "E", , );
  936. GenerateCascadingDropdownListRow(templateWorkbook, "", "客户分类", "Z", "F", , );
  937. GenerateCascadingDropdownListRow(templateWorkbook, "", "客户分级", "AA", "G", , );
  938. //所在地区
  939. string[] regionArray = _tsysManagementBusiness.GetAllTsysCompRegion(_dcContext.CurrentUser.CompanyId.ToString()).Where(x => x.Region_Name != "全部地区").Select(x => x.Region_Name).OrderBy(x => x).ToArray();
  940. GenerateDropdownListRow(templateWorkbook, regionArray, "所在地区", "I", );
  941. //我方负责人
  942. string[] responsPeopleArray = _terpPersonInfoBusiness.GetAllActive().Include(x => x.Org).OrderBy(x => x.EmployeeName).Select(x => x.EmployeeName).ToArray();
  943. //string[] responsPeopleArray = _tsysManagementBusiness.GetAllTsysUser(_dcContext.CurrentUser.CompanyId.ToString()).Select(x => x.UserName).OrderBy(x => x).ToArray();
  944. GenerateDropdownListRow(templateWorkbook, responsPeopleArray, "我方负责人", "Y", );
  945. CheckListRow(templateWorkbook, "客户编码", "A");
  946. using (MemoryStream ms = new MemoryStream())
  947. {
  948. templateWorkbook.Write(ms);
  949. return File(ms.ToArray(), "application/vnd.ms-excel", templateFile);
  950. }
  951. }
  952. }
  953. catch (Exception ex)
  954. {
  955. return View(ex.Message);
  956. }
  957. }
  958. #endregion
  959.  
  960. #region terpPartInStoreInfo 仓库分库存表
  961. private ActionResult ExportTerpPartInStoreInfo()
  962. {
  963. string templateFile = "terpPartInStoreInfo.xlsx";
  964.  
  965. try
  966. {
  967. using (FileStream fs = new FileStream(Server.MapPath(string.Format("{0}{1}", TemplatePath, templateFile)), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
  968. {
  969. XSSFWorkbook templateWorkbook = new XSSFWorkbook(fs);
  970. GenerateDropdownListRow(templateWorkbook, "", "实际仓库类型", "B", );
  971. GenerateDropdownListRow(templateWorkbook, "", "基本仓库类型", "G", );
  972. using (MemoryStream ms = new MemoryStream())
  973. {
  974. templateWorkbook.Write(ms);
  975. return File(ms.ToArray(), "application/vnd.ms-excel", templateFile);
  976. }
  977. }
  978. }
  979. catch (Exception ex)
  980. {
  981. return View(ex.Message);
  982. }
  983. }
  984. #endregion
  985.  
  986. #region TerpPartTotolStoreInfo 总库存
  987. private ActionResult ExportTerpPartTotolStoreInfo()
  988. {
  989. string templateFile = "terpPartTotolStoreInfo.xlsx";
  990.  
  991. try
  992. {
  993. using (FileStream fs = new FileStream(Server.MapPath(string.Format("{0}{1}", TemplatePath, templateFile)), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
  994. {
  995. XSSFWorkbook templateWorkbook = new XSSFWorkbook(fs);
  996. //实际仓库类型
  997. GenerateDropdownListRow(templateWorkbook, "", "实际仓库类型", "B", );
  998.  
  999. //基本仓库类型
  1000. GenerateDropdownListRow(templateWorkbook, "", "基本仓库类型", "E", );
  1001.  
  1002. CheckListRow(templateWorkbook, "编码", "A");
  1003. using (MemoryStream ms = new MemoryStream())
  1004. {
  1005. templateWorkbook.Write(ms);
  1006. return File(ms.ToArray(), "application/vnd.ms-excel", templateFile);
  1007. }
  1008. }
  1009. }
  1010. catch (Exception ex)
  1011. {
  1012. return View(ex.Message);
  1013. }
  1014. }
  1015. #endregion
  1016.  
  1017. #region tsasAgentRegister 合作伙伴
  1018. private ActionResult ExportTsasAgentRegister()
  1019. {
  1020. string templateFile = "tsasAgentRegister.xlsx";
  1021.  
  1022. try
  1023. {
  1024. using (FileStream fs = new FileStream(Server.MapPath(string.Format("{0}{1}", TemplatePath, templateFile)), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
  1025. {
  1026. XSSFWorkbook templateWorkbook = new XSSFWorkbook(fs);
  1027. CheckListRow(templateWorkbook, "公司名称", "A");
  1028. CheckListRow(templateWorkbook, "登录标识", "I");
  1029.  
  1030. //销售代表
  1031. string[] salesPersonArray = _tsysUserBusiness.GetAllActive().OrderBy(x => x.UserName).Select(x => x.UserName).ToArray();
  1032. GenerateDropdownListRow(templateWorkbook, salesPersonArray, "销售代表", "G", );
  1033. //服务状态
  1034. GenerateCascadingDropdownListRow(templateWorkbook, "", "服务状态", "H", "A", , );
  1035. //授权类型
  1036. string[] useStateAgentArray = {"试用","正式" };
  1037. GenerateDropdownListRow(templateWorkbook, useStateAgentArray, "授权类型", "L", );
  1038.  
  1039. using (MemoryStream ms = new MemoryStream())
  1040. {
  1041. templateWorkbook.Write(ms);
  1042. return File(ms.ToArray(), "application/vnd.ms-excel", templateFile);
  1043. }
  1044. }
  1045. }
  1046. catch (Exception ex)
  1047. {
  1048. return View(ex.Message);
  1049. }
  1050. }
  1051. #endregion
  1052.  
  1053. #region tsasRegCompServiceNote 服务记录
  1054. private ActionResult ExportTsasRegCompServiceNote()
  1055. {
  1056. string templateFile = "tsasRegCompServiceNote.xlsx";
  1057.  
  1058. try
  1059. {
  1060. using (FileStream fs = new FileStream(Server.MapPath(string.Format("{0}{1}", TemplatePath, templateFile)), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
  1061. {
  1062. XSSFWorkbook templateWorkbook = new XSSFWorkbook(fs);
  1063. //服务状态
  1064. GenerateCascadingDropdownListRow(templateWorkbook, "", "服务状态", "D", "A", , );
  1065.  
  1066. using (MemoryStream ms = new MemoryStream())
  1067. {
  1068. templateWorkbook.Write(ms);
  1069. return File(ms.ToArray(), "application/vnd.ms-excel", templateFile);
  1070. }
  1071. }
  1072. }
  1073. catch (Exception ex)
  1074. {
  1075. return View(ex.Message);
  1076. }
  1077. }
  1078. #endregion
  1079.  
  1080. #region terpQuoteMnt 报价信息
  1081.  
  1082. private ActionResult ExportTerpQuoteMnt()
  1083. {
  1084. string templateFile = "terpQuoteMnt.xlsx";
  1085. try
  1086. {
  1087. using (FileStream fs = new FileStream(Server.MapPath(string.Format("{0}{1}", TemplatePath, templateFile)), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
  1088. {
  1089. XSSFWorkbook templateWorkbook = new XSSFWorkbook(fs);
  1090. int ddlSheetIndex = ;
  1091. //报价模板
  1092. GenerateDropdownListRow(templateWorkbook, GetTempleteArry(), "报价模板", "B", ddlSheetIndex);
  1093.  
  1094. CheckListRow(templateWorkbook, "客户名称", "A");
  1095. using (MemoryStream ms = new MemoryStream())
  1096. {
  1097. templateWorkbook.Write(ms);
  1098. return File(ms.ToArray(), "application/vnd.ms-excel", templateFile);
  1099. }
  1100. }
  1101. }
  1102. catch (Exception ex)
  1103. {
  1104. return View(ex.Message);
  1105. }
  1106.  
  1107. }
  1108. /// <summary>
  1109. /// 获取模板数组
  1110. /// </summary>
  1111. /// <returns></returns>
  1112. private string[] GetTempleteArry()
  1113. {
  1114. var list= _terpQuotedPriceTemplateBusiness.GetAllActive().ToList();
  1115. List<string> arry=new List<string>();
  1116. for (int i = ; i < list.Count; i++)
  1117. {
  1118. arry.Add(list[i].TemplateName);
  1119. }
  1120. return arry.ToArray();
  1121. }
  1122.  
  1123. #endregion
  1124. }
  1125. }

4。判断Excel是否格式正确,格式正确上传

NPOI 上传Excel功能的更多相关文章

  1. NPOI 上传Excel功能(三)

    4.验证Excel并上传 using DC.BE.Business.SAS; using DC.BE.Business.SYS; using DC.BE.Entity.SAS; using DC.BE ...

  2. NPOI 上传Excel功能(二)

    3.上传文件,写入log using DC.BE.Business.SYS; using DC.BE.Entity.ERP; using DC.BE.Entity.SAS; using DC.BE.E ...

  3. ASP.NET Core 2.2 : 十六.扒一扒新的Endpoint路由方案 try.dot.net 的正确使用姿势 .Net NPOI 根据excel模板导出excel、直接生成excel .Net NPOI 上传excel文件、提交后台获取excel里的数据

    ASP.NET Core 2.2 : 十六.扒一扒新的Endpoint路由方案   ASP.NET Core 从2.2版本开始,采用了一个新的名为Endpoint的路由方案,与原来的方案在使用上差别不 ...

  4. .Net NPOI 上传excel文件、提交后台获取excel里的数据

    1.导入NPOI.dll 2.添加类NPOIExcel.cs using System; using System.Collections.Generic; using System.Text; us ...

  5. 文件一键上传、汉字转拼音、excel文件上传下载功能模块的实现

    ----------------------------------------------------------------------------------------------[版权申明: ...

  6. 微信小程序上传Excel文本文件功能

    问题: 在开发过程中会发现微信小程序有很多功能都还不能满足我们的需求,谁叫客户就是上帝呢,前几天小编遇到了这么个问题,就是用微信小程序上传文件,但是还以为微信带有这个模块,可是查了许久还是没有找到,只 ...

  7. java的poi技术下载Excel模板上传Excel读取Excel中内容(SSM框架)

    使用到的jar包 JSP: client.jsp <%@ page language="java" contentType="text/html; charset= ...

  8. WEB文件上传下载功能

    WEB文件上传下载在日常工作中经常用到的功能 这里用到JS库 http://files.cnblogs.com/meilibao/ajaxupload.3.5.js 上传代码段(HTML) <% ...

  9. java上传excel到后台解析入库

    背景:最近需要做一个excel模板导入的功能,以便用户可以自己增删改查数据,当然,只有特别的用户才能有此权限,捋了捋思路,还是从前端写起 实现: 页面最后的效果如下,可以自己修改,删除,导入导出数据, ...

随机推荐

  1. python:while循环、运算符、初始编码

    while循环 while -- 关键字 while 条件: 缩进代码块 以上循环是(死循环) 终止循环的方法 1.break 跳出循环,并且把循环给干掉了 2.continue 跳出本次循环,继续下 ...

  2. java对象比较

    public class InternDemo { public static void main(String[] args){ /* jdk7版本之后 字符串常量池从Perm Space移到Jav ...

  3. WebBench压力测试工具(详细源码注释+分析)

    本文适合人群:对WebBench实现感兴趣的人 WebBench原理: Linux下使用的服务器压力测试工具,利用fork建立多个子进程,每个子进程在测试时间内不断发送请求报文,建立多个连接,然后由父 ...

  4. Linux进程管理 (7)实时调度

    关键词:RT.preempt_count.RT patch. 除了CFS调度器之外,还包括重要的实时调度器,有两种RR和FIFO调度策略.本章只是一个简单的介绍. 更详细的介绍参考<Linux进 ...

  5. Android如果有一个任意写入的漏洞,如何将写权限转成执行权限

    这个题目我以为是考的怎么进行提权,结果原来是这样的: . DexClassLoader 动态载入应用可写入的 dex 可执行文件 . java.lang.Runtime.exec 方法执行应用可写入的 ...

  6. 史上最全的Spring Boot配置文件详解

    Spring Boot在工作中是用到的越来越广泛了,简单方便,有了它,效率提高不知道多少倍.Spring Boot配置文件对Spring Boot来说就是入门和基础,经常会用到,所以写下做个总结以便日 ...

  7. 【开源】微信小程序、小游戏以及 Web 通用 Canvas 渲染引擎 - Cax

    Cax 小程序.小游戏以及 Web 通用 Canvas 渲染引擎 Github → https://github.com/dntzhang/cax 点我看看 DEMO 小程序 DEMO 正在审核中敬请 ...

  8. 2018年计划小目标(9月)PMP

    从6.23结束敏捷的系统贯穿学习考试,6.24开始做传统项目管理,系统学习计划,打包报考,(╥╯^╰╥):ACP+实战+PMP+软考,历时两个月 每天上下班路上3个小时,听录音,(报的远程班,倍速听了 ...

  9. CSS 伪类 (Pseudo-classes)实例

    CSS 伪类 (Pseudo-classes)实例CSS 伪类用于向某些选择器添加特殊的效果在支持 CSS 的浏览器中,链接的不同状态都可以不同的方式显示,这些状态包括:活动状态,已被访问状态,未被访 ...

  10. 单链表的基本操作--c++

    #include <iostream> //实现单链表的建立,测长和打印 #include <string> using namespace std; struct node ...