public void CreateExcelFile <T>(CreateExcelAction <T> createExcelAction, List <T> list, ExcelFormat excelFormat) { //建立Excel 2003檔案 IWorkbook wb = new XSSFWorkbook(); ISheet ws = wb.CreateSheet("Class"); XSSFRow row = (XSSFRow)ws.CreateRow(0); row.Height = 440; ICellStyle positionStyle = wb.CreateCellStyle(); positionStyle.WrapText = true; positionStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center; positionStyle.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center; foreach (var item in excelFormat.ColumnFormats) { ws.SetColumnWidth(excelFormat.ColumnFormats.IndexOf(item), item.CoiumnWidth); CreateCell(row, excelFormat.ColumnFormats.IndexOf(item), item.ColumnTitle, positionStyle); } int rowIndex = 1; foreach (var storeData in list) { createExcelAction(wb, ws, positionStyle, ref rowIndex, storeData); } FileStream file = new FileStream(string.Concat(AppSettingConfig.FilePath(), @"\", excelFormat.FileName, DateTime.Now.ToString("yyyyMMdd"), ".xlsx"), FileMode.Create);//產生檔案 wb.Write(file); file.Close(); }
public void CreateExcelFile(IWorkbook wb, ExcelContent excelContent) { foreach (var excelSheet in excelContent.ExcelSheetContents) { ISheet ws = wb.CreateSheet(excelSheet.SheetName); ws.SetMargin(MarginType.LeftMargin, excelSheet.LeftMargin); ws.SetMargin(MarginType.RightMargin, excelSheet.RightMargin); ws.SetMargin(MarginType.TopMargin, excelSheet.TopMargin); ws.SetMargin(MarginType.BottomMargin, excelSheet.BottomMargin); XSSFRow row = (XSSFRow)ws.CreateRow(0); row.Height = excelSheet.ColumnHeight; foreach (ExcelColumnContent columnContent in excelSheet.ExcelColumnContents) { if (columnContent.Width != 0) { ws.SetColumnWidth(excelSheet.ExcelColumnContents.ToList().IndexOf(columnContent), columnContent.Width); } CreateCell(row, excelSheet.ExcelColumnContents.ToList().IndexOf(columnContent), columnContent.CellValue, columnContent.CellStyle); } int rowIndex = 1; foreach (ExcelRowContent rowContent in excelSheet.ExcelRowContents) { XSSFRow rowTextile = (XSSFRow)ws.CreateRow(rowIndex); rowTextile.Height = rowContent.Height; for (int cellIndex = 0; cellIndex < rowContent.ExcelCellContents?.Count; cellIndex++) { if (double.TryParse(rowContent.ExcelCellContents.ElementAt(cellIndex).CellValue, out double cellValue)) { CreateCell(rowTextile, cellIndex, cellValue, rowContent.ExcelCellContents.ElementAt(cellIndex).CellStyle); } else { CreateCell(rowTextile, cellIndex, rowContent.ExcelCellContents.ElementAt(cellIndex).CellValue, rowContent.ExcelCellContents.ElementAt(cellIndex).CellStyle); } if (rowContent.ExcelCellContents.ElementAt(cellIndex).CellRangeAddress != null) { ws.AddMergedRegion(rowContent.ExcelCellContents.ElementAt(cellIndex).CellRangeAddress); } } rowIndex++; } } FileStream file = new FileStream(string.Concat(AppSettingConfig.FilePath(), @"\", excelContent.FileName, ".xlsx"), FileMode.Create);//產生檔案 wb.Write(file); file.Close(); }
public List <string> GetExcelSheetName() { IWorkbook workbook = null; //新建IWorkbook對象 string fileName = string.Concat(AppSettingConfig.FilePath(), "/", AppSettingConfig.StoreManageFileName()); FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); workbook = new XSSFWorkbook(fileStream); //xlsx數據讀入workbook var sheetListName = new List <string>(); for (int sheetCount = 1; sheetCount < workbook.NumberOfSheets; sheetCount++) { var sheetName = workbook.GetSheetName(sheetCount); //獲取第i個工作表 sheetListName.Add(sheetName); } return(sheetListName); }
private void CheckBox_Click(object sender, RoutedEventArgs e) { CheckBox checkBox = (CheckBox)sender; ExternalDataHelper externalDataHelper = new ExternalDataHelper(); TextileNameMappings = externalDataHelper.GetTextileNameMappings(); if (checkBox.IsChecked ?? false) { string fileNamePath = string.Concat(AppSettingConfig.FilePath(), "/", AppSettingConfig.StoreManageFileName()); Tuple <List <string>, IWorkbook> tuple = ExcelModule.GetExcelWorkbook(fileNamePath); TextileInventoryHeader textileInventoryHeader = ExcelModule.GetShippingDate(tuple.Item2.GetSheetAt(1)); Workbook = tuple.Item2; Window parentWindow = Window.GetWindow(this); var textileNameMapping = TextileNameMappings.ToList().Find(f => f.ProcessOrder.Contains(ProcessOrder == null ? string.Empty : ProcessOrder.Fabric)); List <TextileColorInventory> selectedTextiles = new List <TextileColorInventory>(); if (textileNameMapping != null) { ExcelHelper excelHelper = new ExcelHelper(); foreach (var item in textileNameMapping.Inventory) { selectedTextiles.AddRange(excelHelper.GetInventoryData(Workbook, item)); } textileInventoryHeader.Textile = ProcessOrder.Fabric; } InventoryListDialog = new InventoryListDialog(AppSettingConfig.StoreManageFileName(), textileInventoryHeader, selectedTextiles) { Owner = Window.GetWindow(this), Top = parentWindow.Top + parentWindow.Height, Left = parentWindow.Left, Height = 300 }; InventoryListDialog.Show(); InventoryListDialog.Closed += InventoryListDialog_Closed; InventoryUpdateTime.Content = DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss"); } else { InventoryListDialog.Close(); } }
/// <summary> /// 讀取Excel後匯出Excel /// </summary> /// <typeparam name="T"></typeparam> /// <param name="readExcelAction"></param> /// <param name="createExcelAction"></param> /// <param name="timeRange"></param> /// <param name="excelFormat"></param> public void InventoryCheckSheet <T>(ReadExcelAction <T> readExcelAction, CreateExcelAction <T> createExcelAction, int timeRange, ExcelFormat excelFormat) { IWorkbook workbook = null; //新建IWorkbook對象 string fileName = string.Concat(AppSettingConfig.FilePath(), "/", AppSettingConfig.StoreManageFileName()); FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); workbook = new XSSFWorkbook(fileStream); //xlsx數據讀入workbook var list = new List <T>(); for (int sheetCount = 1; sheetCount < workbook.NumberOfSheets; sheetCount++) { ISheet sheet = workbook.GetSheetAt(sheetCount); //獲取第i個工作表 IRow row; var firstRow = sheet.GetRow(0); for (int rowIndex = 1; rowIndex <= sheet.LastRowNum; rowIndex++) //對工作表每一行 { if (rowIndex > 70) { break; } row = sheet.GetRow(rowIndex); //row讀入第i行數據 if (row != null) { //該筆資料沒有顏色則不讀取該Row if (row.GetCell(1) == null) { break; } readExcelAction(list, row, sheet.SheetName, timeRange); } else { break; } } } CreateExcelFile(createExcelAction, list, excelFormat); }
public InventoryReturnModel() { string fileName = string.Concat(AppSettingConfig.FilePath(), "\\庫存管理", ".xlsx"); IWorkbook workbook = null; //新建IWorkbook對象 using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { workbook = new XSSFWorkbook(fs); } for (int sheetCount = 1; sheetCount < workbook.NumberOfSheets; sheetCount++) { ISheet sheet = workbook.GetSheetAt(sheetCount); //獲取第i個工作表 sheet.ForceFormulaRecalculation = true; for (int rowCount = 1; rowCount <= sheet.LastRowNum; rowCount++) { IRow row = sheet.GetRow(rowCount); //確認該列是否有值 if (row == null) { break; } ICell inventoryCell = row.GetCell(ExcelInventoryColumnIndexEnum.Inventory.ToInt()); //確認布種顏色是否有值 if (inventoryCell == null) { break; } ICell inventoryDifferentCell = row.GetCell(ExcelInventoryColumnIndexEnum.DifferentCylinder.ToInt()); //確認布種顏色是否為數值,且不同缸的值如為null或是有數值,則可繼續運算 try { if (inventoryCell.CellType == CellType.Numeric && (inventoryDifferentCell == null || inventoryDifferentCell.CellType == CellType.Numeric || inventoryDifferentCell.CellType == CellType.Blank)) { ICell countInventoryCell = row.GetCell(ExcelInventoryColumnIndexEnum.CountInventory.ToInt()); //檢查計算庫存量是否和原庫存量是否相同 double inventory = inventoryCell.NumericCellValue; double inventoryDifferent = inventoryDifferentCell != null ? inventoryDifferentCell.NumericCellValue : 0; double countInventory = countInventoryCell.NumericCellValue; double totalInventory = inventory + inventoryDifferent; if (totalInventory != countInventory) { double shippingDate1 = GetExcelNumericCellValue(row, ExcelInventoryColumnIndexEnum.ShippingDate1); double shippingDate2 = GetExcelNumericCellValue(row, ExcelInventoryColumnIndexEnum.ShippingDate2); double shippingDate3 = GetExcelNumericCellValue(row, ExcelInventoryColumnIndexEnum.ShippingDate3); double shippingDate4 = GetExcelNumericCellValue(row, ExcelInventoryColumnIndexEnum.ShippingDate4); double shippingDate5 = GetExcelNumericCellValue(row, ExcelInventoryColumnIndexEnum.ShippingDate5); double shippingDate6 = GetExcelNumericCellValue(row, ExcelInventoryColumnIndexEnum.ShippingDate6); double shippingDate7 = GetExcelNumericCellValue(row, ExcelInventoryColumnIndexEnum.ShippingDate7); double shippingDate8 = GetExcelNumericCellValue(row, ExcelInventoryColumnIndexEnum.ShippingDate8); double shippingDate9 = GetExcelNumericCellValue(row, ExcelInventoryColumnIndexEnum.ShippingDate9); double totalShipping = shippingDate1 + shippingDate2 + shippingDate3 + shippingDate4 + shippingDate5 + shippingDate6 + shippingDate7 + shippingDate8 + shippingDate9; double finalCountInventory = totalInventory - totalShipping; //如果不同缸為0,則直接修改庫存量 if (inventoryDifferent == 0) { inventoryCell.SetCellValue(finalCountInventory); } //否則判斷數量是否有出完一缸 else { if (inventory > totalShipping) { inventoryCell.SetCellValue(inventory - totalShipping); } else { inventoryDifferentCell.SetCellType(CellType.Blank); inventoryCell.SetCellValue(finalCountInventory); } } if (shippingDate1 != 0) { row.GetCell(ExcelInventoryColumnIndexEnum.ShippingDate1.ToInt()).SetCellType(CellType.Blank); } if (shippingDate2 != 0) { row.GetCell(ExcelInventoryColumnIndexEnum.ShippingDate2.ToInt()).SetCellType(CellType.Blank); } if (shippingDate3 != 0) { row.GetCell(ExcelInventoryColumnIndexEnum.ShippingDate3.ToInt()).SetCellType(CellType.Blank); } if (shippingDate4 != 0) { row.GetCell(ExcelInventoryColumnIndexEnum.ShippingDate4.ToInt()).SetCellType(CellType.Blank); } if (shippingDate5 != 0) { row.GetCell(ExcelInventoryColumnIndexEnum.ShippingDate5.ToInt()).SetCellType(CellType.Blank); } if (shippingDate6 != 0) { row.GetCell(ExcelInventoryColumnIndexEnum.ShippingDate6.ToInt()).SetCellType(CellType.Blank); } if (shippingDate7 != 0) { row.GetCell(ExcelInventoryColumnIndexEnum.ShippingDate7.ToInt()).SetCellType(CellType.Blank); } if (shippingDate8 != 0) { row.GetCell(ExcelInventoryColumnIndexEnum.ShippingDate8.ToInt()).SetCellType(CellType.Blank); } if (shippingDate9 != 0) { row.GetCell(ExcelInventoryColumnIndexEnum.ShippingDate9.ToInt()).SetCellType(CellType.Blank); } } } } catch (Exception ex) { string errorMessage = string.Concat("----錯誤來源----\n", "布種名稱:" + sheet.SheetName, "\n資料行數:", rowCount, "\n" + ex.StackTrace); MessageBox.Show(errorMessage); throw ex; } } } using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write)) { workbook.Write(fs); } }
/// <summary> /// 取得Excel每日出貨清單 /// </summary> /// <param name="shippedDate"></param> /// <returns></returns> public List <StoreSearchData <StoreSearchColorDetail> > GetExcelDailyShippedList(DateTime?shippedDate) { IWorkbook workbook = null; //新建IWorkbook對象 string fileName = string.Concat(AppSettingConfig.FilePath(), "/", AppSettingConfig.StoreManageFileName()); FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); workbook = new XSSFWorkbook(fileStream); //xlsx數據讀入workbook var list = new List <StoreSearchData <StoreSearchColorDetail> >(); var selectedDateTime = shippedDate == null?DateTime.Now.ToString("MM/dd") : shippedDate?.ToString("MM/dd"); var currentDateValue = "出貨" + selectedDateTime; for (int sheetCount = 1; sheetCount < workbook.NumberOfSheets; sheetCount++) { ISheet sheet = workbook.GetSheetAt(sheetCount); //獲取第i個工作表 IRow row; var currentDateCellIndex = -1; var firstRow = sheet.GetRow(0); for (int columnIndex = 5; columnIndex < 14; columnIndex++) { var cell = firstRow.GetCell(columnIndex); var cellValue = cell.StringCellValue; if (cellValue == currentDateValue) { currentDateCellIndex = columnIndex; break; } } var colorList = new List <StoreData>(); for (int rowIndex = 1; rowIndex <= sheet.LastRowNum; rowIndex++) //對工作表每一行 { if (rowIndex > 120) { break; } row = sheet.GetRow(rowIndex); //row讀入第i行數據 if (row != null) { if (row.GetCell(ExcelEnum.ExcelInventoryColumnIndexEnum.ColorName.ToInt()) == null) { break; } if (row.GetCell(currentDateCellIndex) != null && row.GetCell(currentDateCellIndex).CellType != CellType.String && row.GetCell(currentDateCellIndex).NumericCellValue != 0) { var countInventory = row.GetCell(ExcelEnum.ExcelInventoryColumnIndexEnum.CountInventory.ToInt()); if (countInventory == null || string.IsNullOrEmpty(countInventory.ToString()) || (countInventory.CellType == CellType.Formula && countInventory.CachedFormulaResultType == CellType.Error)) { continue; } var cellValue = countInventory.NumericCellValue; //獲取i行j列數據 //清單裡若沒有該布種則加入 if (list.Where(w => w.TextileName == sheet.SheetName).Count() == 0) { list.Add(new StoreSearchData <StoreSearchColorDetail> { TextileName = sheet.SheetName, StoreSearchColorDetails = new List <StoreSearchColorDetail>() }); } var currentTextile = list.Where(w => w.TextileName == sheet.SheetName).First(); currentTextile.StoreSearchColorDetails.Add(new StoreSearchColorDetail { ColorName = row.GetCell(ExcelEnum.ExcelInventoryColumnIndexEnum.ColorName.ToInt()) == null ? "" : row.GetCell(ExcelEnum.ExcelInventoryColumnIndexEnum.ColorName.ToInt()).ToString(), FabricFactory = row.GetCell(ExcelEnum.ExcelInventoryColumnIndexEnum.FabricFactory.ToInt()) == null ? "" : row.GetCell(ExcelEnum.ExcelInventoryColumnIndexEnum.FabricFactory.ToInt()).ToString(), ClearFactory = row.GetCell(ExcelEnum.ExcelInventoryColumnIndexEnum.ClearFactory.ToInt()) == null ? "" : row.GetCell(ExcelEnum.ExcelInventoryColumnIndexEnum.ClearFactory.ToInt()).ToString(), ShippedCount = Convert.ToInt32(row.GetCell(currentDateCellIndex).NumericCellValue), CountInventory = cellValue.ToString(), CheckDate = row.GetCell(ExcelEnum.ExcelInventoryColumnIndexEnum.CheckDate.ToInt()) == null ? "" : row.GetCell(ExcelEnum.ExcelInventoryColumnIndexEnum.CheckDate.ToInt()).ToString() }); } } else { break; } } } return(list); }
public ShipFeatureViewModel(string shipFeatureDate) { string defaultDate = DateTime.Now.ToString("yyyyMMdd"); string[] dateNumber = shipFeatureDate.Split('-'); string fileNameDate = string.Concat(AppSettingConfig.FilePath(), "\\出貨", dateNumber[0].Length > 5 ? dateNumber[0] : defaultDate, "-", dateNumber[0].Length > 5 ? dateNumber[1] : dateNumber[0], ".xlsx"); //IEnumerable<string> shipFileName = Directory.GetFiles(AppSettingConfig.FilePath(), fileNameDate).Select(System.IO.Path.GetFileName).OrderByDescending(o => o); IWorkbook workbook = null; //新建IWorkbook對象 using (FileStream fs = new FileStream(fileNameDate, FileMode.Open, FileAccess.Read)) { workbook = new XSSFWorkbook(fs); } IEnumerable <TrashItem> trashItems = TrashModule.GetTrashItems().Where(w => w.I_03 != null).OrderBy(o => o.I_01); ExternalDataHelper externalDataHelper = new ExternalDataHelper(); IEnumerable <TextileNameMapping> textileNameMappings = externalDataHelper.GetTextileNameMappings(); for (int sheetCount = 1; sheetCount < workbook.NumberOfSheets; sheetCount++) { ISheet sheet = workbook.GetSheetAt(sheetCount); //獲取第i個工作表 string textileName = null; sheet.SetColumnWidth(4, 12200); ICell customerCell = sheet.GetRow(4).GetCell(2); IEnumerable <TrashCustomer> trashCustomers = TrashModule.GetCustomerList().Where(w => customerCell.StringCellValue.Contains(w.C_NAME)); if (trashCustomers != null && trashCustomers.FirstOrDefault() != null) { customerCell.SetCellValue(string.Concat(customerCell.StringCellValue, "-", trashCustomers.FirstOrDefault().CARD_NO, trashCustomers.FirstOrDefault().C_NAME)); } for (int rowCount = 6; rowCount <= 18; rowCount++) { IRow row = sheet.GetRow(rowCount); if (row == null) { break; } ICell textileNameCell = row.GetCell(1); if (textileNameCell != null && textileNameCell.StringCellValue != null && textileNameCell.StringCellValue != "") { textileName = textileNameCell.StringCellValue; } ICell colorCell = row.GetCell(4); if (colorCell == null) { break; } string colorCellValue = colorCell.CellType == CellType.String ? colorCell.StringCellValue : colorCell.NumericCellValue.ToString(); if (colorCellValue == null || colorCellValue == "") { break; } string textileColor = colorCellValue.Split('-')[0]; int textileColorNumber = colorCellValue.Split('-').Length >= 2 ? colorCellValue.Split('-')[1].ToInt() : 0; if (textileColorNumber / 7 >= 1) { rowCount += textileColorNumber / 7; } TrashItem trashItem = externalDataHelper.GetTrashItemFromInventoryMapping(trashItems, textileName, textileColor, textileNameMappings); string accountFactoryID = string.Empty; string accountTextileID = string.Empty; string accountTextileName = string.Empty; if (trashItem == null) { } else { accountFactoryID = trashItem.F_01; accountTextileID = trashItem.I_01; accountTextileName = trashItem.I_03; } string shipFeatureString = colorCellValue + "*" + accountFactoryID + "_" + accountTextileID + "-" + accountTextileName; colorCell.SetCellValue(shipFeatureString); IFont font = workbook.CreateFont(); font.Color = HSSFColor.Blue.Index2; font.FontName = "新細明體"; font.IsBold = true; colorCell.RichStringCellValue.ApplyFont( shipFeatureString.Length - 1 - accountTextileID.Length - accountTextileName.Length , shipFeatureString.Length - accountTextileName.Length - 1, font); } } using (FileStream fs = new FileStream(fileNameDate, FileMode.Create, FileAccess.Write)) { workbook.Write(fs); } }
private void InventoryNumberRangeSearchExecute() { StoreDataList.Clear(); IWorkbook workbook = null; //新建IWorkbook對象 string fileName = string.Concat(AppSettingConfig.FilePath(), "/", AppSettingConfig.StoreManageFileName()); FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); workbook = new XSSFWorkbook(fileStream); //xlsx數據讀入workbook Regex checkStoreAreaPattern = new Regex(string.Concat("(^", StoreArea.Replace(",", ")+|(^"), ")+")); Regex checkExceptAreaPattern = new Regex(string.Concat("(", ExceptArea.Replace(",", ")+|("), ")+")); Regex checkTextileNamePattern = new Regex(string.Concat("(", TextileName.Replace(",", ")+|("), ")+")); for (int sheetCount = 1; sheetCount < workbook.NumberOfSheets; sheetCount++) { ISheet sheet = workbook.GetSheetAt(sheetCount); //獲取第i個工作表 IRow row; // = sheet.GetRow(0); //新建當前工作表行數據 if (!checkTextileNamePattern.IsMatch(sheet.SheetName)) { continue; } var colorList = new List <StoreData>(); for (int rowNumber = 1; rowNumber <= sheet.LastRowNum; rowNumber++) //對工作表每一行 { if (rowNumber > 70) { break; } row = sheet.GetRow(rowNumber); //row讀入第i行數據 if (row != null) { if (row.GetCell((int)ExcelEnum.ExcelInventoryColumnIndexEnum.ColorName) == null) { break; } ICell countInventory = row.GetCell((int)ExcelEnum.ExcelInventoryColumnIndexEnum.CountInventory); if (countInventory == null || string.IsNullOrEmpty(countInventory.ToString()) || (countInventory.CellType == CellType.Formula && countInventory.CachedFormulaResultType == CellType.Error)) { continue; } double cellValue = countInventory.NumericCellValue; //獲取i行j列數據 string storeArea = row.GetCell((int)ExcelEnum.ExcelInventoryColumnIndexEnum.StorageSpaces) == null ? "" : row.GetCell((int)ExcelEnum.ExcelInventoryColumnIndexEnum.StorageSpaces).ToString(); if (cellValue <= MaxNumber && cellValue >= MinNumber && checkStoreAreaPattern.IsMatch(storeArea) && !checkExceptAreaPattern.IsMatch(storeArea)) { colorList.Add(new StoreData { ColorName = row.GetCell((int)ExcelEnum.ExcelInventoryColumnIndexEnum.ColorName) == null ? "" : row.GetCell((int)ExcelEnum.ExcelInventoryColumnIndexEnum.ColorName).ToString(), StoreArea = storeArea, FabricFactory = row.GetCell((int)ExcelEnum.ExcelInventoryColumnIndexEnum.FabricFactory) == null ? "" : row.GetCell((int)ExcelEnum.ExcelInventoryColumnIndexEnum.FabricFactory).ToString(), ClearFactory = row.GetCell((int)ExcelEnum.ExcelInventoryColumnIndexEnum.ClearFactory) == null ? "" : row.GetCell((int)ExcelEnum.ExcelInventoryColumnIndexEnum.ClearFactory).ToString(), CountInventory = cellValue.ToString(), CheckDate = row.GetCell((int)ExcelEnum.ExcelInventoryColumnIndexEnum.CheckDate) == null ? "" : row.GetCell((int)ExcelEnum.ExcelInventoryColumnIndexEnum.CheckDate).ToString() }); } else { continue; } } else { break; } } DateTime result; var soretColorList = colorList.OrderBy(o => o.FabricFactory).ThenBy(o => o.ClearFactory).ThenBy(o => Convert.ToDouble(o.CountInventory)).ThenByDescending(O => DateTime.TryParse(O.CheckDate, out result) == true ? result : DateTime.Now.AddDays(-360)); if (soretColorList.Count() > 0) { StoreDataList.Add(new StoreData { TextileName = sheet.SheetName, ColorName = "", CountInventory = "" }); } foreach (var item in soretColorList) { StoreDataList.Add(item); } } fileStream.Close(); workbook.Close(); }