private void ToolStripMenuItemExport_Click(object sender, EventArgs e) { string excelPath = System.IO.Path.GetDirectoryName(labActionModelPath.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(labActionModelPath.Text) + ".xlsx"; ReoGridReport.Save(excelPath, unvell.ReoGrid.IO.FileFormat.Excel2007, System.Text.Encoding.UTF8); MessageBox.Show("导出成功!"); if (checkOpenFile.Checked == true) { Process.Start(excelPath); } }
/// <summary> /// 把BOM清单插入表格式 /// </summary> private void InsertBOMtoReoGrid() { ResetGridTable(); var sheet = ReoGridReport.CurrentWorksheet; //bomItems.Sort(); string xuhao = ""; for (int i = 0; i < bomItems.Count; i++) { string Qianzhui = bomItems[i].level; string Qianzhui2 = ""; try { Qianzhui2 = bomItems[i - 1].level; } catch (Exception) { Qianzhui2 = "."; } string tempA = ""; if (i == 0) { tempA = "1"; xuhao = "1"; } else { tempA = sheet[string.Join("", "A", i + 1)].ToString(); xuhao = GetNextLevel(tempA, Qianzhui2, Qianzhui); } int actionRow = i + 2; sheet[string.Join("", "A", actionRow)] = xuhao; sheet[string.Join("", "B", actionRow)] = bomItems[i].name2; sheet[string.Join("", "C", actionRow)] = bomItems[i].material; string tempsize = bomItems[i].size; sheet[string.Join("", "D", actionRow)] = bomItems[i].qty.ToString(); //备料 尺寸 长宽厚 string tempCommect = bomItems[i].comment; sheet[string.Join("", "E", actionRow)] = tempCommect; } sheet.RowCount = bomItems.Count + 1; sheet.AutoFitColumnWidth(0, true); sheet.AutoFitColumnWidth(1, true); sheet.AutoFitColumnWidth(2, true); sheet.AutoFitColumnWidth(3, false); sheet.AutoFitColumnWidth(4, false); sheet.SetColumnsWidth(3, 3, 45); sheet.SetColumnsWidth(4, 3, 45); sheet.ColumnHeaders["A"].Style.HorizontalAlign = ReoGridHorAlign.Left; sheet.ColumnHeaders["B"].Style.HorizontalAlign = ReoGridHorAlign.Left; sheet.ColumnHeaders["C"].Style.HorizontalAlign = ReoGridHorAlign.Left; sheet.ColumnHeaders["D"].Style.HorizontalAlign = ReoGridHorAlign.Left; sheet.ColumnHeaders["E"].Style.HorizontalAlign = ReoGridHorAlign.Center; ReoGridReport.DoAction(sheet, new SetRangeBorderAction(new RangePosition(0, 0, sheet.RowCount, sheet.ColumnCount), BorderPositions.All, new RangeBorderStyle { Color = unvell.ReoGrid.Graphics.SolidColor.Black, Style = BorderLineStyle.Solid }) ); sheet.SetRangeStyles("A1:E1", new WorksheetRangeStyle { Flag = PlainStyleFlag.BackColor, BackColor = Color.LightGray }); //var header = sheet.ColumnHeaders["A"]; //header.Style.HorizontalAlign = ReoGridHorAlign.Center; }