// // TAB separated // public bool ExportTabSeparated(string fn, ExportTableAasEntitiesList iterateAasEntities, string tab = "\t") { // access if (!IsValid()) { return(false); } using (var f = new StreamWriter(fn)) { // header var proc = new ItemProcessor(this, null); for (int ri = 0; ri < this.Rows; ri++) { var line = ""; for (int ci = 0; ci < this.Cols; ci++) { // get cell record var cr = GetHeaderCell(ri, ci); // process text proc.ProcessCellRecord(cr); // add if (line != "") { line += tab; } line += cr.Text; } f.WriteLine(line); } // elements foreach (var item in iterateAasEntities) { // create processing proc = new ItemProcessor(this, item); proc.Start(); proc.ReplaceNewlineWith = ""; // for TSF, this is not possible! var lines = new List <string>(); // all elements for (int ri = 0; ri < this.Rows; ri++) { var line = ""; for (int ci = 0; ci < this.Cols; ci++) { // get cell record var cr = GetElementsCell(ri, ci); // process text proc.ProcessCellRecord(cr); // add if (line != "") { line += tab; } line += cr.Text; } lines.Add(line); } // export really? if (proc.NumberReplacements > 0) { foreach (var line in lines) { f.WriteLine(line); } } } } return(true); }
public bool ExportExcel(string fn, ExportTableAasEntitiesList iterateAasEntities) { // access if (!IsValid()) { return(false); } // // Excel init // Excel with pure OpenXML is very complicated, therefore ClosedXML was used on the top // see: https://github.com/closedxml/closedxml/wiki/Basic-Table // var wb = new XLWorkbook(); var ws = wb.Worksheets.Add("AAS Export"); // // Export // int rowIdx = 1; int startRowIdx = rowIdx; // header if (true) { var proc = new ItemProcessor(this, null); proc.Start(); for (int ri = 0; ri < this.Rows; ri++) { for (int ci = 0; ci < this.Cols; ci++) { // get cell record var cr = GetHeaderCell(ri, ci); // process text proc.ProcessCellRecord(cr); // add ExportExcel_AppendTableCell(ws, cr, rowIdx + ri, 1 + ci); } } rowIdx += this.Rows; } // elements if (true) { foreach (var item in iterateAasEntities) { // create processing var proc = new ItemProcessor(this, item); proc.Start(); // all elements for (int ri = 0; ri < this.Rows; ri++) { for (int ci = 0; ci < this.Cols; ci++) { // get cell record var cr = GetElementsCell(ri, ci); // process text proc.ProcessCellRecord(cr); // add ExportExcel_AppendTableCell(ws, cr, rowIdx + ri, 1 + ci); } } // export really? if (proc.NumberReplacements > 0) { // advance rowIdx += this.Rows; } else { // delete this out var rng = ws.Range(rowIdx, 1, rowIdx + this.Rows - 1, 1 + this.Cols - 1); rng.Clear(); } } } // some modifications on the whole table? if (true) { if (rowIdx > startRowIdx + 1) { // do a explicit process of overall table cell var proc = new ItemProcessor(this, null); proc.Start(); var cr = GetHeaderCell(0, 0); proc.ProcessCellRecord(cr); // borders? if (cr.Frame != null) { var rng = ws.Range(startRowIdx, 1, rowIdx - 1, 1 + this.Cols - 1); if (cr.Frame == "1") { rng.Style.Border.OutsideBorder = XLBorderStyleValues.Thin; rng.Style.Border.InsideBorder = XLBorderStyleValues.Thin; } if (cr.Frame == "2") { rng.Style.Border.OutsideBorder = XLBorderStyleValues.Thick; rng.Style.Border.InsideBorder = XLBorderStyleValues.Thin; } if (cr.Frame == "3") { rng.Style.Border.OutsideBorder = XLBorderStyleValues.Thick; rng.Style.Border.InsideBorder = XLBorderStyleValues.Thick; } } // column widths ws.Columns(1, this.Cols).AdjustToContents(); } } // // End // // Save the new worksheet. wb.SaveAs(fn); return(true); }
public bool ExportWord(string fn, ExportTableAasEntitiesList iterateAasEntities) { // access if (!IsValid()) { return(false); } // Create Document using (WordprocessingDocument wordDocument = WordprocessingDocument.Create(fn, WordprocessingDocumentType.Document, true)) { // // Word init // see: http://www.ludovicperrichon.com/create-a-word-document-with-openxml-and-c/#table // // Add a main document part. MainDocumentPart mainPart = wordDocument.AddMainDocumentPart(); // Create the document structure and add some text. mainPart.Document = new Document(); Body body = mainPart.Document.AppendChild(new Body()); // // Export // // make a table Table table = body.AppendChild(new Table()); // do a process on overall table cells if (true) { var proc = new ItemProcessor(this, null); proc.Start(); var cr = GetHeaderCell(0, 0); proc.ProcessCellRecord(cr); // do some borders? if (cr?.Frame != null) { UInt32Value thickOuter = 6; UInt32Value thickInner = 6; if (cr.Frame == "2") { thickOuter = 12; } if (cr.Frame == "3") { thickOuter = 12; } var tblProperties = table.AppendChild(new TableProperties()); var tblBorders = tblProperties.AppendChild(new TableBorders()); tblBorders.Append( new TopBorder() { Val = new EnumValue <BorderValues>(BorderValues.Thick), Color = "000000", Size = thickOuter }); tblBorders.Append( new LeftBorder() { Val = new EnumValue <BorderValues>(BorderValues.Thick), Color = "000000", Size = thickOuter }); tblBorders.Append( new RightBorder() { Val = new EnumValue <BorderValues>(BorderValues.Thick), Color = "000000", Size = thickOuter }); tblBorders.Append( new BottomBorder() { Val = new EnumValue <BorderValues>(BorderValues.Thick), Color = "000000", Size = thickOuter }); tblBorders.Append( new InsideHorizontalBorder() { Val = new EnumValue <BorderValues>(BorderValues.Thick), Color = "000000", Size = thickInner }); tblBorders.Append( new InsideVerticalBorder() { Val = new EnumValue <BorderValues>(BorderValues.Thick), Color = "000000", Size = thickInner }); } } // header if (true) { var proc = new ItemProcessor(this, null); proc.Start(); for (int ri = 0; ri < this.Rows; ri++) { // new row TableRow tr = table.AppendChild(new TableRow()); // over cells for (int ci = 0; ci < this.Cols; ci++) { // get cell record var cr = GetHeaderCell(ri, ci); // process text proc.ProcessCellRecord(cr); // add ExportWord_AppendTableCell(tr, cr); } } } // elements if (true) { foreach (var item in iterateAasEntities) { // create processing var proc = new ItemProcessor(this, item); proc.Start(); // remember rows in order to can deleten them later var newRows = new List <TableRow>(); // all elements for (int ri = 0; ri < this.Rows; ri++) { // new row TableRow tr = table.AppendChild(new TableRow()); newRows.Add(tr); // over cells for (int ci = 0; ci < this.Cols; ci++) { // get cell record var cr = GetElementsCell(ri, ci); // process text proc.ProcessCellRecord(cr); // add ExportWord_AppendTableCell(tr, cr); } } // export really? if (proc.NumberReplacements > 0) { // advance } else { // delete this out foreach (var r in newRows) { table.RemoveChild(r); } } } } // // End // } return(true); }