public async Task <ResponseObject <string> > ExportBomTemplate() { try { CurrentUser currentUser = TokenManager.GetCurentUserbyToken(HttpContext.Request.Headers); var result = await _service.ExportBomTemplate(359, currentUser); //return result; ExportTemplateVM <TMMBOMDetailQueryExcelModel> model = new ExportTemplateVM <TMMBOMDetailQueryExcelModel>(); model.Entitys = result.Data.TMMBOMDetailQueryExcelList == null ? new List <TMMBOMDetailQueryExcelModel>() : result.Data.TMMBOMDetailQueryExcelList; model.Columns = new List <string>() { "ItemName", "MaterialName", "PartName", "LengthValue", "WidthValue", "NumValue", "WideValue", "LossValue", "SingleValue" }; model.Titles = new List <string>() { "ItemName", "MaterialName", "PartName", "LengthValue", "WidthValue", "NumValue", "WideValue", "LossValue", "SingleValue" }; model.HeaderText = "BOM模板"; model.TableName = "BOM模板"; model.FillRow = 6; model.Path = Path.Combine(AppContext.BaseDirectory, "Template", "ExportBomTemplate.xlsx"); Stream stream = ExcelHelp.ExportExcelByTemplate <TMMBOMDetailQueryExcelModel>(model); string fileName = "生产单模板-有配色方案.xlsx"; Dictionary <string, string> headsSend = new Dictionary <string, string>(); headsSend.Add(TokenConfig.Instace.TokenKey, Request.Headers[TokenConfig.Instace.TokenKey]); var filePath = RestfulApiClient.UploadFile(RestfulApiClient.UplaodUrl, "api/files/upload", headsSend, stream, fileName); return(ResponseUtil <string> .SuccessResult(filePath.ToString())); } catch (Exception ex) { return(ResponseUtil <string> .FailResult(null, ex.ToString())); } }
public async Task <ResponseObject <string> > ExportStaReport(string requestObject) { try { var request = JsonConvert.DeserializeObject <RequestGet>(requestObject); CurrentUser currentUser = TokenManager.GetCurentUserbyToken(HttpContext.Request.Headers); var result = await _inventoryReportService.LoadReport(request, currentUser); ExportTemplateVM <InventoryResultModel> model = new ExportTemplateVM <InventoryResultModel>(); model.Entitys = result.Data == null ? new List <InventoryResultModel>() : result.Data; model.Columns = new List <string>() { "MaterialCode", "MaterialName", "Spec", "ColorName", "BatchNo", "WarehouseCode", "WarehouseName", "BaseUnitName", "BaseUnitNumber", "WarehouseUnitName", "WarehouseAmount", "WarehouseRate", "InDate", "ShelfLife", "ValidDate", "Remark", }; model.Titles = new List <string>() { "MaterialCode", "MaterialName", "Spec", "ColorName", "BatchNo", "WarehouseCode", "WarehouseName", "BaseUnitName", "BaseUnitNumber", "WarehouseUnitName", "WarehouseAmount", "WarehouseRate", "InDate", "ShelfLife", "ValidDate", "Remark", }; model.HeaderText = "库存统计"; model.TableName = "库存统计"; model.FillRow = 3; model.Path = Path.Combine(AppContext.BaseDirectory, "Template", "InventoryReport.xlsx"); Stream stream = ExcelHelp.ExportExcelByTemplate <InventoryResultModel>(model); string fileName = "库存统计.xlsx"; Dictionary <string, string> headsSend = new Dictionary <string, string>(); headsSend.Add(TokenConfig.Instace.TokenKey, Request.Headers[TokenConfig.Instace.TokenKey]); var filePath = RestfulApiClient.UploadFile(RestfulApiClient.UplaodUrl, "api/files/upload", headsSend, stream, fileName); return(ResponseUtil <string> .SuccessResult(filePath.ToString())); } catch (Exception ex) { return(ResponseUtil <string> .FailResult(null, ex.ToString())); } }
public static MemoryStream ExportExcelByTemplate <T>(ExportTemplateVM <T> model) { DataTable dt = ListToDataTable <T>(model.Entitys, model.TableName, model.Columns, model.Titles); return(ExportExcelByTemplate(dt, model.Path, model.FillRow)); }