/// <summary> /// create the row header of the data table of the chart /// </summary> /// <param name="table"></param> /// <returns></returns> private RowHeader CreateRowHeader(Table table) { RowHeader rowheader = new RowHeader (table); int startColumnIndex = m_tableData.startcell .columnIndex ; int endColumnIndex = m_tableData.endcell .columnIndex ; Row row = new Row (table); Cell cell = this.CreateNullStringCell (table); row.Cells .Add (cell); for(int i=startColumnIndex; i<=endColumnIndex; i++) { Cell tempCell = new Cell (table.Document); tempCell.OfficeValueType ="string"; Paragraph paragraph = new Paragraph (m_document); string content =((char)('A'+i-1)).ToString ()+"ĮŠ"; paragraph.TextContent .Add (new SimpleText (m_document ,content)); tempCell.Content .Add (paragraph); row.Cells .Add (tempCell); } rowheader.RowCollection .Add (row); return rowheader; }
private void WriteTable(IMultipleRowsProducer rp, Table table, IGenerationContext context) { DataRow[] rows = rp.GetValue(context).ToArray(); if (rows.Length > 0) { DataTable ptab = rows.First().Table; for (int iCol = 0; iCol < ptab.Columns.Count; iCol++) { table.ColumnCollection.Add(new Column(table, string.Empty)); } for (int iRow = -1; iRow < rows.Length; iRow++) { Row row = new Row(table); table.RowCollection.Add(row); for (int iCol = 0; iCol < ptab.Columns.Count; iCol++) { Cell cell = new Cell(table); object value = (iRow == -1) ? ptab.Columns[iCol].ColumnName : rows[iRow][iCol]; CreateAddSimpleText(table.Document, cell.Content, value); row.CellCollection.Add(cell); } } } }
public void CreateSimpleTable() { //Create new spreadsheet document SpreadsheetDocument spreadsheetDocument = new SpreadsheetDocument(); spreadsheetDocument.New(); //Create a new table Table table = new Table(spreadsheetDocument, "First", "tablefirst"); //Create a new cell, without any extra styles Cell cell = table.CreateCell("cell001"); cell.OfficeValueType = "string"; //Set full border cell.CellStyle.CellProperties.Border = Border.NormalSolid; //Add a paragraph to this cell Paragraph paragraph = ParagraphBuilder.CreateSpreadsheetParagraph( spreadsheetDocument); //Add some text content paragraph.TextContent.Add(new SimpleText(spreadsheetDocument, "Some text")); //Add paragraph to the cell cell.Content.Add(paragraph); //Insert the cell at row index 2 and column index 3 //All need rows, columns and cells below the given //indexes will be build automatically. table.InsertCellAt(2, 3, cell); //Insert table into the spreadsheet document spreadsheetDocument.TableCollection.Add(table); spreadsheetDocument.SaveTo(AARunMeFirstAndOnce.outPutFolder+"simple.ods"); }
/// <summary> /// Initializes a new instance of the <see cref="Cell"/> class. /// This will create an empty cell that use the default cell style /// </summary> /// <param name="table">The table.</param> public Cell(Table table) { this.Table = table; this.Document = table.Document; this.NewXmlNode(null); this.InitStandards(); }
public SpreadsheetReportGenerator () { //Create new spreadsheet document document = new SpreadsheetDocument(); document.New(); table = TableBuilder.CreateSpreadsheetTable (document, "First", ""); }
public static Chart CreateChartByAxisName(Table table,ChartTypes type,string CellRange,string AxisXName,string AxisYName) { Chart chart = CreateChart (table,type,CellRange); chart.XAxisName = AxisXName; chart.YAxisName = AxisYName; return chart; }
public void CreateSimpleTable() { //Create new spreadsheet document _spreadsheetDocument2 = new SpreadsheetDocument(); _spreadsheetDocument2.Load(AARunMeFirstAndOnce.inPutFolder+@"blank.ods"); //Create a new table Table table = new Table(_spreadsheetDocument2, "First", "tablefirst"); table.Rows.Add(new Row(table)); //Create a new cell, without any extra styles Cell cell = new Cell(_spreadsheetDocument2, "cell001"); cell.OfficeValueType = "string"; //Set full border cell.CellStyle.CellProperties.Border = Border.NormalSolid; //Add a paragraph to this cell Paragraph paragraph = ParagraphBuilder.CreateSpreadsheetParagraph( _spreadsheetDocument2); //Add some text content String cellText = "Some text"; paragraph.TextContent.Add(new SimpleText(_spreadsheetDocument2, cellText)); //Add paragraph to the cell cell.Content.Add(paragraph); //Insert the cell at row index 2 and column index 3 //All need rows, columns and cells below the given //indexes will be build automatically. table.InsertCellAt(1, 1, cell); //Insert table into the spreadsheet document _spreadsheetDocument2.TableCollection.Add(table); // Test inserted content Assert.AreEqual(_spreadsheetDocument2.TableCollection[0], table); String text = _spreadsheetDocument2.TableCollection[0].Rows[1].Cells[1].Node.InnerText; Assert.AreEqual(text, cellText); }
public static Chart CreateChart(Table table,ChartTypes type,string CellRange) { Chart chart = new Chart (table,"ch1"); chart.ChartType = type.ToString (); chart.CreateFromCellRange (CellRange); return chart; }
public void CreateRowsAndColumns() { SpreadsheetDocument doc = new SpreadsheetDocument (); doc.New (); Table table = new Table (doc,"tab1","tab1"); for(int i=1; i<=4; i++) { for(int j=1; j<=5;j++) { Cell cell = table.CreateCell (); cell.OfficeValueType ="float"; Paragraph paragraph = new Paragraph (doc); string text= (j+i-1).ToString(); paragraph.TextContent .Add (new SimpleText ( doc,text)); cell.Content.Add(paragraph); cell.OfficeValueType = "string"; cell.OfficeValue = text; table.InsertCellAt (i, j, cell); } } Assert.AreEqual(5, table.Rows.Count); for (int i = 1; i < 4; i++) { Row row = table.Rows[i]; Assert.AreEqual(6, row.Cells.Count); } }
/// <summary> /// Initializes a new instance of the <see cref="RowHeader"/> class. /// </summary> /// <param name="table">The table.</param> public RowHeader(Table table) { this.Table = table; this.Document = table.Document; this.InitStandards(); // this.RowCollection = new RowCollection(); this.NewXmlNode(); }
/// <summary> /// Initializes a new instance of the <see cref="Column"/> class. /// </summary> /// <param name="table">The table.</param> /// <param name="styleName">Name of the style.</param> public Column(Table table, string styleName) { this.Table = table; this.Document = table.Document; this.NewXmlNode(styleName); this.ColumnStyle = new ColumnStyle(this.Document, styleName); this.Document.Styles.Add(this.ColumnStyle); }
/// <summary> /// /// </summary> /// <param name="table"></param> /// <returns>the null string cell</returns> /// <example ><texp/></example> private Cell CreateNullStringCell(Table table) { Cell cell = new Cell (table.Document); Paragraph paragraph = new Paragraph (m_document ); cell.Content .Add (paragraph); return cell; }
public static Chart CreateChartByTitle(Table table,string CellRange,ChartTypes type,string title,string xPosition,string yPosition,string xAxisname,string yAxisname) { Chart chart = CreateChart(table,type,CellRange); chart.ChartTitle .SetTitle (title); chart.ChartTitle .SvgX = xPosition; chart.ChartTitle .SvgY = yPosition; chart.XAxisName =xAxisname; chart.YAxisName =yAxisname; return chart; }
/// <summary> /// Creates the text document table. /// </summary> /// <param name="document">The document.</param> /// <param name="tableName">Name of the table.</param> /// <param name="styleName">Name of the style.</param> /// <param name="rows">The rows.</param> /// <param name="columns">The columns.</param> /// <param name="width">The width.</param> /// <param name="useTableRowHeader">if set to <c>true</c> [use table row header].</param> /// <param name="useBorder">The useBorder.</param> /// <returns></returns> public static Table CreateTextDocumentTable( AODL.Document.TextDocuments.TextDocument document, string tableName, string styleName, int rows, int columns, double width, bool useTableRowHeader, bool useBorder) { string tableCnt = document.DocumentMetadata.TableCount.ToString(); Table table = new Table(document, tableName, styleName); table.TableStyle.TableProperties.Width = width.ToString().Replace(",",".")+"cm"; for(int i=0; i<columns; i++) { Column column = new Column(table, "co"+tableCnt+i.ToString()); column.ColumnStyle.ColumnProperties.Width = GetColumnCellWidth(columns, width); table.ColumnCollection.Add(column); } if (useTableRowHeader) { rows--; RowHeader rowHeader = new RowHeader(table); Row row = new Row(table, "roh1"+tableCnt); for(int i=0; i<columns; i++) { Cell cell = new Cell(table.Document, "rohce"+tableCnt+i.ToString()); if (useBorder) cell.CellStyle.CellProperties.Border = Border.NormalSolid; row.Cells.Add(cell); } rowHeader.RowCollection.Add(row); table.RowHeader = rowHeader; } for(int ir=0; ir<rows; ir++) { Row row = new Row(table, "ro"+tableCnt+ir.ToString()); for(int ic=0; ic<columns; ic++) { Cell cell = new Cell(table.Document, "ce"+tableCnt+ir.ToString()+ic.ToString()); if (useBorder) cell.CellStyle.CellProperties.Border = Border.NormalSolid; row.Cells.Add(cell); } table.Rows.Add(row); } return table; }
public void CloneTable() { TextDocument docuemnt = new TextDocument(); docuemnt.New(); Table table = new Table(docuemnt, "table name", "table style"); int numberOfColumns = 10; int numberOfRows = 10; // prepare data // add columns for (int i = 0; i < numberOfColumns; i++) { table.ColumnCollection.Add(new Column(table, "style name " + i)); } Row row = null; // Add rows for (int i = 0; i < 2; i++) { row = new Row(table); for (int i1 = 0; i1 < numberOfColumns; i1++) { Paragraph par = ParagraphBuilder.CreateStandardTextParagraph(docuemnt); par.TextContent.AddRange(TextBuilder.BuildTextCollection(docuemnt, (i * numberOfColumns).ToString() + i1)); row.Cells.Add(new Cell(table.Document, "cell style " + i)); //row.Cells.Add(new Cell(table.Document)); row.Cells[i1].Content.Add(par); } table.Rows.Insert(0, row); } // clone many rows row = table.Rows[0]; using (IPerformanceCounter counter = new PerformanceCounter()) { for (int i = 0; i < numberOfRows; i++) { Row newRow = new Row(table, row.StyleName); foreach (Cell rowCell in row.Cells) { Cell cell = new ContentMocker().CloneAny(rowCell) as Cell; newRow.Cells.Add(cell); } } Console.WriteLine(string.Format( "Test executed in {0} seconds", counter.GetSeconds())); } }
/// <summary> /// Converts the specified table. /// </summary> /// <param name="table">The table.</param> /// <returns>The PDF table.</returns> public iTextSharp.text.pdf.PdfPTable Convert(Table table) { try { iTextSharp.text.pdf.PdfPTable pdfTable; TableLayoutInfo tableLayout = new TableLayoutInfo(); tableLayout.AnalyzeTableLayout(table); if (tableLayout.CellWidths != null) { pdfTable = new iTextSharp.text.pdf.PdfPTable(tableLayout.CellWidths); } else { pdfTable = new iTextSharp.text.pdf.PdfPTable(tableLayout.MaxCells); } if (table.Style != null && table.Style is TableStyle && ((TableStyle)table.Style).TableProperties != null) { //((TableStyle)table.Style).TableProperties.Width } foreach(Row row in table.Rows) { foreach(Cell cell in row.Cells) { iTextSharp.text.pdf.PdfPCell pdfCell = new iTextSharp.text.pdf.PdfPCell(); if (cell.ColumnRepeating != null && Int32.Parse(cell.ColumnRepeating) > 0) { pdfCell.Colspan = Int32.Parse(cell.ColumnRepeating); } foreach(iTextSharp.text.IElement pdfElement in MixedContentConverter.GetMixedPdfContent(cell.Content)) { pdfCell.AddElement(pdfElement); } pdfTable.AddCell(pdfCell); } } //pdfTable = this.SetProperties(table, pdfTable, maxCells); return pdfTable; } catch(Exception) { throw; } }
public void AutomaticallCreateRows() { SpreadsheetDocument doc = new SpreadsheetDocument (); doc.New (); Table table = new Table (doc,"tab1","tab1"); for(int i=1; i<=1; i++) { for(int j=1; j<=1;j++) { Cell cell = table.CreateCell (); cell.OfficeValueType ="float"; Paragraph paragraph = new Paragraph (doc); string text= (j+i-1).ToString(); paragraph.TextContent .Add (new SimpleText ( doc,text)); cell.Content.Add(paragraph); cell.OfficeValueType = "string"; cell.OfficeValue = text; table.InsertCellAt (i, j, cell); } } // test that we have this number of rows and cells Assert.AreEqual(2, table.Rows.Count); for (int i = 1; i < table.Rows.Count; i++) { Row row = table.Rows[i]; Assert.AreEqual(2, row.Cells.Count); } // force to insert more cells table.InsertCellAt(5, 5, table.CreateCell () ); // assert, that the cells were added Assert.AreEqual(6, table.Rows.Count); for (int i = 0; i < table.Rows.Count; i++) { Row row = table.Rows[i]; Assert.AreEqual(6, row.Cells.Count); } }
/// <summary> /// Analyzes the table layout. /// </summary> /// <param name="table">The table.</param> public void AnalyzeTableLayout(Table table) { try { this.GetTableWidth(table); this._maxCells = 1; foreach(Row r in table.Rows) { if (r.Cells.Count > this._maxCells) { this._maxCells = r.Cells.Count; } } this.CalulateCellWidths(table.ColumnCollection); } catch(Exception) { throw; } }
public void CreateNewChart() { SpreadsheetDocument doc = new SpreadsheetDocument (); doc.New (); Table table = new Table (doc,"tab1","tab1"); for(int i=1; i<=1; i++) { for(int j=1; j<=6;j++) { Cell cell = table.CreateCell (); cell.OfficeValueType ="float"; Paragraph paragraph = new Paragraph (doc); string text= (j+i-1).ToString(); paragraph.TextContent .Add (new SimpleText ( doc,text)); cell.Content.Add(paragraph); cell.OfficeValueType = "string"; cell.OfficeValue = text; table.InsertCellAt (i, j, cell); } } Chart chart=ChartBuilder.CreateChartByAxisName (table,ChartTypes.bar ,"A1:E4","years","dollars"); Assert.AreEqual(7, table.Rows[1].Cells.Count); Assert.AreEqual(6, table.Rows[2].Cells.Count); Assert.AreEqual(6, table.Rows[3].Cells.Count); Assert.AreEqual(6, table.Rows[4].Cells.Count); /*Chart chart = new Chart (table,"ch1"); chart.ChartType=ChartTypes.bar .ToString () ; chart.XAxisName ="yeer"; chart.YAxisName ="dollar"; chart.CreateFromCellRange ("A1:E4"); chart.EndCellAddress ="tab1.K17";*/ table.InsertChartAt ("G2",chart); doc.Content .Add (table); doc.SaveTo(Path.Combine(AARunMeFirstAndOnce.outPutFolder, @"NewChartOne.ods")); }
public static Chart CreateChartByAxises(Table table,string CellRange,ChartTypes type,int dimension) { Chart chart = CreateChart(table,type,CellRange); if (dimension==1) { ChartAxis Yaxis = CreateAxis(chart,"y","primary-y"); chart.ChartPlotArea .AxisCollection .Add (Yaxis); Yaxis.AxesStyle .AxesProperties .DisplayLabel = "true"; } else if (dimension==2) { ChartAxis Yaxis = CreateAxis(chart,"y","primary-y"); chart.ChartPlotArea .AxisCollection .Add (Yaxis); ChartAxis Xaxis = CreateAxis(chart,"x","primary-x"); chart.ChartPlotArea .AxisCollection .Add (Xaxis); Yaxis.AxesStyle .AxesProperties .DisplayLabel = "true"; Xaxis.AxesStyle .AxesProperties .DisplayLabel = "true"; } else { ChartAxis Yaxis = CreateAxis(chart,"y","primary-y"); chart.ChartPlotArea .AxisCollection .Add (Yaxis); ChartAxis Xaxis = CreateAxis(chart,"x","primary-x"); chart.ChartPlotArea .AxisCollection .Add (Xaxis); ChartAxis Zaxis = CreateAxis(chart,"z","primary-z"); chart.ChartPlotArea .AxisCollection .Add (Zaxis); Yaxis.AxesStyle .AxesProperties .DisplayLabel = "true"; Xaxis.AxesStyle .AxesProperties .DisplayLabel = "true"; Zaxis.AxesStyle .AxesProperties .DisplayLabel = "true"; chart.ChartPlotArea .PlotAreaStyle.PlotAreaProperties.ThreeDimensional="true"; } return chart; }
public override void Export(IEnumerable<List<CellInfo>> exportInfo) { SpreadsheetDocument spreadsheetDocument = new SpreadsheetDocument(); spreadsheetDocument.New(); Table table = new Table(spreadsheetDocument, "DataGrid", string.Empty); int rowIndex = 0; foreach (List<CellInfo> cellInfos in exportInfo) { for (int columnIndex = 0; columnIndex < cellInfos.Count; columnIndex++) { CellInfo cellInfo = cellInfos[columnIndex]; Cell cell = table.CreateCell(); Paragraph paragraph = ParagraphBuilder.CreateSpreadsheetParagraph(spreadsheetDocument); SimpleText fText = new SimpleText(spreadsheetDocument, (cellInfo.Value ?? string.Empty).ToString()); paragraph.TextContent.Add(fText); cell.Content.Add(paragraph); table.InsertCellAt(rowIndex, columnIndex, cell); } rowIndex++; } spreadsheetDocument.TableCollection.Add(table); Save(spreadsheetDocument); }
/// <summary> /// Creates the document forms. /// </summary> /// <param name="node">The node.</param> public void CreateCellForms(Table table) { /// TODO: ADD IMPLEMENTATION! try { XmlNode nodeOfficeForms; nodeOfficeForms = table.Node.SelectSingleNode("office:forms", _document.NamespaceManager); if (nodeOfficeForms != null) { foreach(XmlNode nodeChild in nodeOfficeForms) { if (this._document is SpreadsheetDocument) { ODFForm f = CreateForm(nodeChild); table.Forms.Add(f); } } nodeOfficeForms.RemoveAll(); } } catch(Exception ex) { throw new AODLException("Exception while processing forms.", ex); } }
public ChartBuilderHelper(IDocument document, ChartPlotArea chartPlotArea, CellRanges tableData) { this.m_document = document; this.ChartPlotArea = chartPlotArea; this.m_tableData = tableData; startRowIndex = m_tableData.startcell.rowIndex ; endRowIndex = m_tableData.endcell .rowIndex ; startColumnIndex = m_tableData.startcell .columnIndex ; endColumnIndex = m_tableData.endcell .columnIndex ; table = new Table (m_document ,"local-table",null); DataTable = m_tableData.table ; }
public class_traslate_spreadsheet(string query_sql, string[] args_names_field, string[] args_type_field, bool typetext, string[] args_field_text, string name_field_text, bool more_title, string[] args_more_title) { //Console.WriteLine(name_field_text+" nombre del campo"); int files_field = 0; string [] array_field_text = new string[args_field_text.Length]; connectionString = conexion_a_DB._url_servidor + conexion_a_DB._port_DB + conexion_a_DB._usuario_DB + conexion_a_DB._passwrd_user_DB; nombrebd = conexion_a_DB._nombrebd; //Create new spreadsheet open document (.ods) AODL.Document.SpreadsheetDocuments.SpreadsheetDocument spreadsheetDocument = new AODL.Document.SpreadsheetDocuments.SpreadsheetDocument(); spreadsheetDocument.New(); //Create a new table AODL.Document.Content.Tables.Table table = new AODL.Document.Content.Tables.Table(spreadsheetDocument, "hoja1", "tablefirst"); NpgsqlConnection conexion; conexion = new NpgsqlConnection(connectionString + nombrebd); // Verifica que la base de datos este conectada try{ conexion.Open(); NpgsqlCommand comando; comando = conexion.CreateCommand(); comando.CommandText = query_sql; Console.WriteLine(comando.CommandText); comando.ExecuteNonQuery(); comando.Dispose(); NpgsqlDataReader lector = comando.ExecuteReader(); // Creando los nombres de ancabezado de los campos for (int colum_field = 0; colum_field < args_names_field.Length; colum_field++) { AODL.Document.Content.Tables.Cell cell = table.CreateCell(); //cell.OfficeValueType ="float"; AODL.Document.Content.Text.Paragraph paragraph = new AODL.Document.Content.Text.Paragraph(spreadsheetDocument); string text = (string)args_names_field[colum_field].ToString().Trim(); paragraph.TextContent.Add(new AODL.Document.Content.Text.SimpleText(spreadsheetDocument, text)); cell.Content.Add(paragraph); cell.OfficeValueType = "string"; cell.OfficeValue = text; table.InsertCellAt(files_field, colum_field, cell); } if (typetext == true) { // Creando los nombres de ancabezado de los campos cuando son de tipo text (almacenado en una tabla tipo text) for (int colum_field2 = 0; colum_field2 < args_field_text.Length; colum_field2++) { AODL.Document.Content.Tables.Cell cell = table.CreateCell(); //cell.OfficeValueType ="float"; AODL.Document.Content.Text.Paragraph paragraph = new AODL.Document.Content.Text.Paragraph(spreadsheetDocument); string text = (string)args_field_text[colum_field2].ToString().Trim(); paragraph.TextContent.Add(new AODL.Document.Content.Text.SimpleText(spreadsheetDocument, text)); cell.Content.Add(paragraph); cell.OfficeValueType = "string"; cell.OfficeValue = text; table.InsertCellAt(files_field, colum_field2 + args_names_field.Length, cell); } } if (more_title == true) { int title_field_text = 0; if (typetext == true) { title_field_text = args_field_text.Length; } // Creando los nombres de ancabezado de los campos cuando son de tipo text (almacenado en una tabla tipo text) for (int colum_field3 = 0; colum_field3 < args_more_title.Length; colum_field3++) { AODL.Document.Content.Tables.Cell cell = table.CreateCell(); //cell.OfficeValueType ="float"; AODL.Document.Content.Text.Paragraph paragraph = new AODL.Document.Content.Text.Paragraph(spreadsheetDocument); string text = (string)args_more_title[colum_field3].ToString().Trim(); paragraph.TextContent.Add(new AODL.Document.Content.Text.SimpleText(spreadsheetDocument, text)); cell.Content.Add(paragraph); cell.OfficeValueType = "string"; cell.OfficeValue = text; table.InsertCellAt(files_field, colum_field3 + args_names_field.Length + title_field_text, cell); } } files_field++; string texto = ""; while (lector.Read()) { for (int colum_field = 0; colum_field < args_names_field.Length; colum_field++) { AODL.Document.Content.Tables.Cell cell = table.CreateCell(); //cell.OfficeValueType ="float"; AODL.Document.Content.Text.Paragraph paragraph = new AODL.Document.Content.Text.Paragraph(spreadsheetDocument); string text = lector[(string)args_names_field[colum_field]].ToString().Trim(); paragraph.TextContent.Add(new AODL.Document.Content.Text.SimpleText(spreadsheetDocument, text)); cell.Content.Add(paragraph); cell.OfficeValueType = (string)args_type_field [colum_field]; cell.OfficeValue = text; table.InsertCellAt(files_field, colum_field, cell); } if (typetext == true) { texto = (string)lector[name_field_text]; // puede ser una campo de la base de datos tipo Text char[] delimiterChars = { '\n' }; // delimitador de Cadenas char[] delimiterChars1 = { ';' }; // delimitador de Cadenas //string texto = "1;daniel; ;olivares;cuevas"; //"2;genaro;cuevas;bazaldua\n"+ //"3;gladys;perez;orellana\n"; string[] words = texto.Split(delimiterChars); // Separa las Cadenas if (texto != "") { // Recorre la variable foreach (string s in words) { if (s.Length > 0) { string texto1 = (string)s; string[] words1 = texto1.Split(delimiterChars1); //for (int i = 1; i <= 6; i++){ int i = 0; int i2 = 1; foreach (string s1 in words1) { //Console.WriteLine(s1.ToString()); if (i2 <= args_field_text.Length) { array_field_text[i] = s1.ToString(); } i++; i2++; } } } for (int i = 0; i < array_field_text.Length; i++) { //Console.WriteLine(array_field_text[i]); AODL.Document.Content.Tables.Cell cell = table.CreateCell(); //cell.OfficeValueType ="float"; AODL.Document.Content.Text.Paragraph paragraph = new AODL.Document.Content.Text.Paragraph(spreadsheetDocument); string text = (string)array_field_text[i]; paragraph.TextContent.Add(new AODL.Document.Content.Text.SimpleText(spreadsheetDocument, text)); cell.Content.Add(paragraph); cell.OfficeValueType = "string"; cell.OfficeValue = text; table.InsertCellAt(files_field, i + args_names_field.Length, cell); } } else { } } files_field++; } conexion.Close(); //Insert table into the spreadsheet document spreadsheetDocument.TableCollection.Add(table); spreadsheetDocument.SaveTo("export.ods"); // open the document automatic System.Diagnostics.Process.Start("export.ods"); }catch (NpgsqlException ex) { MessageDialog msgBoxError = new MessageDialog(MyWinError, DialogFlags.DestroyWithParent, MessageType.Error, ButtonsType.Close, "PostgresSQL error: {0}", ex.Message); msgBoxError.Run(); msgBoxError.Destroy(); } /* * // Leyendo el archivo .ods * spreadsheetDocument.Load("export.ods"); * Assert.IsNotNull(spreadsheetDocument.TableCollection, "Table collection must exits."); * //Assert.IsTrue(spreadsheetDocument.TableCollection.Count == 6, "There must be 3 tables available."); * * int paso = spreadsheetDocument.TableCollection.Count; * * Console.WriteLine(paso.ToString()); * int i2 = 0; // current row index * int ii = 0; // current cell index * string innerText = ""; // current inner text * try{ * //Assert.IsTrue(spreadsheetDocument.TableCollection[0].Rows.Count == 5, "There must be 6 rows available."); * for(i2= 0; i2 < spreadsheetDocument.TableCollection[0].Rows.Count; i2++){ * string contents = "Row " + i2 + ": "; * //Assert.IsTrue(spreadsheetDocument.TableCollection[0].Rows[i2].Cells.Count == 3, "There must be 3 cells available."); * for(ii = 0; ii < spreadsheetDocument.TableCollection[0].Rows[i2].Cells.Count; ii++){ * innerText = spreadsheetDocument.TableCollection[0].Rows[i2].Cells[ii].Node.InnerText; * if (spreadsheetDocument.TableCollection[0].Rows[i2].Cells[ii].OfficeValue != null){ * contents += spreadsheetDocument.TableCollection[0].Rows[i2].Cells[ii].OfficeValue.ToString() + " "; * }else{ * contents += innerText + " "; * } * } * Console.WriteLine(contents); * } * }catch(System.Exception ex){ * string where = "occours in Row " + i2.ToString() + " and cell " + ii.ToString() + " last cell content " + innerText + "\n\n"; * Console.WriteLine(where + ex.Message + "\n\n" + ex.StackTrace); * } */ /* * // Usando libreria SmartXLS * WorkBook book = new WorkBook(); * * try{ * //Sets the number of worksheets in this workbook * book.NumSheets = 2; * // set sheet names * book.setSheetName(0, "hoja1"); // renombrando la pestaña * book.setSheetName(1, "hoja2"); // renombrando la pestaña * book.Sheet = 0; * // book.setText(Fila, columna , "texto"); * book.setText(0, 0, "foliodeservicio"); * book.setText(0, 1, "descripcion_producto"); * book.setText(0, 2, "idproducto"); * book.setText(0, 3, "cantidadaplicada"); * book.setText(0, 4, "preciounitario"); * book.setText(0, 5, "ppcantidad"); * book.setText(0, 6, "fechcreacion"); * book.setText(0, 7, "descripcion_admisiones"); * book.setText(0, 8, "idtipoadmision"); * book.setText(0, 9, "descripcion_grupo_producto"); * book.setText(0, 10, "aplicar_iva"); * * NpgsqlConnection conexion; * conexion = new NpgsqlConnection (connectionString+nombrebd); * // Verifica que la base de datos este conectada * try{ * conexion.Open (); * NpgsqlCommand comando; * comando = conexion.CreateCommand (); * comando.CommandText = "SELECT osiris_erp_cobros_deta.folio_de_servicio AS foliodeservicio,descripcion_producto,to_char(osiris_erp_cobros_deta.id_producto,'999999999999') AS idproducto, "+ * "to_char(osiris_erp_cobros_deta.cantidad_aplicada,'99999.99') AS cantidadaplicada,to_char(osiris_erp_cobros_deta.precio_producto,'99999999.99') AS preciounitario,"+ * "to_char(osiris_erp_cobros_deta.cantidad_aplicada * osiris_erp_cobros_deta.precio_producto,'99999999.99') AS ppcantidad,"+ * "to_char(osiris_erp_cobros_deta.fechahora_creacion,'dd-MM-yyyy HH24:mi:ss') AS fechcreacion, osiris_his_tipo_admisiones.descripcion_admisiones,"+ * "osiris_erp_cobros_deta.id_tipo_admisiones AS idtipoadmision,descripcion_grupo_producto,osiris_productos.aplicar_iva," + * "to_char(osiris_erp_cobros_deta.id_secuencia,'9999999999') AS secuencia " + * "FROM osiris_erp_cobros_deta,osiris_productos,osiris_his_tipo_admisiones,osiris_grupo_producto " + * "WHERE osiris_erp_cobros_deta.id_producto = osiris_productos.id_producto " + * "AND osiris_erp_cobros_deta.id_tipo_admisiones = osiris_his_tipo_admisiones.id_tipo_admisiones " + * "AND osiris_productos.id_grupo_producto = osiris_grupo_producto.id_grupo_producto " + * "AND osiris_erp_cobros_deta.eliminado = false " + * "AND osiris_erp_cobros_deta.folio_de_servicio IN('"+numeroatencion_+"') " + * "ORDER BY to_char(osiris_erp_cobros_deta.fechahora_creacion,'yyyy-MM-dd HH24:mm:ss'),osiris_erp_cobros_deta.id_tipo_admisiones ASC," + * "osiris_productos.id_grupo_producto;"; * comando.ExecuteNonQuery(); comando.Dispose(); * //Console.WriteLine(comando.CommandText); * NpgsqlDataReader lector = comando.ExecuteReader (); * while (lector.Read()){ * book.setNumber(number_file, 0, int.Parse(numeroatencion_)); * book.setText(number_file, 1, (string) lector["descripcion_producto"]); * book.setText(number_file, 2, (string) lector["idproducto"]); * number_file++; * } * conexion.Close(); * book.write("export.xls"); * * System.Diagnostics.Process.Start("export.xls"); * * * }catch(NpgsqlException ex){ * MessageDialog msgBoxError = new MessageDialog (MyWinError,DialogFlags.DestroyWithParent, * MessageType.Error, * ButtonsType.Close,"PostgresSQL error: {0}",ex.Message); * msgBoxError.Run (); msgBoxError.Destroy(); * } * * * }catch (System.Exception ex){ * Console.Error.WriteLine(ex); * } */ }
/// <summary> /// create the row serial cell /// </summary> /// <param name="table"></param> /// <param name="SerialNum"></param> /// <returns></returns> private Cell CreateRowSerialCell(Table table,int SerialNum) { Cell cell = new Cell (table.Document); cell.OfficeValueType ="string"; Paragraph paragraph = new Paragraph (m_document); string content = SerialNum.ToString ()+"ŠŠ"; paragraph.TextContent .Add (new SimpleText (m_document,content)); cell.Content .Add (paragraph); return cell; }
/// <summary> /// Initializes a new instance of the <see cref="Row"/> class. /// </summary> /// <param name="table">The table.</param> /// <param name="styleName">Name of the style.</param> public Row(Table table, string styleName) { this.Table = table; this.Document = table.Document; this.NewXmlNode(styleName); this.RowStyle = Document.StyleFactory.Request<RowStyle>(styleName); this.InitStandards(); }
/// <summary> /// Initializes a new instance of the <see cref="Row"/> class. /// </summary> /// <param name="table">The table.</param> /// <param name="styleName">Name of the style.</param> public Row(Table table, string styleName) { this.Table = table; this.Document = table.Document; this.NewXmlNode(styleName); this.RowStyle = new RowStyle(this.Document, styleName); this.Document.Styles.Add(this.RowStyle); this.InitStandards(); }
/// <summary> /// Creates the table. /// </summary> /// <param name="tableNode">The tablenode.</param> /// <returns></returns> private Table CreateTable(XmlNode tableNode) { try { //Create a new table Table table = new Table(this._document, tableNode); ContentCollection iColl = new ContentCollection(); //Recieve the table style IStyle tableStyle = this._document.Styles.GetStyleByName(table.StyleName); if (tableStyle != null) table.Style = tableStyle; else { this.OnWarning(new AODLWarning("Couldn't recieve a TableStyle.", tableNode)); } //Create the table content foreach(XmlNode nodeChild in table.Node.ChildNodes) { IContent iContent = this.CreateContent(nodeChild); if (iContent != null) { //iColl.Add(iContent); AddToCollection(iContent, iColl); } else { this.OnWarning(new AODLWarning("Couldn't create IContent from a table node. Content is unknown table content!", iContent.Node)); } } table.Node.InnerText = ""; foreach(IContent iContent in iColl) { if (iContent is Column) { ((Column)iContent).Table = table; table.ColumnCollection.Add(iContent as Column); } else if (iContent is Row) { ((Row)iContent).Table = table; table.Rows.Add(iContent as Row); } else if (iContent is RowHeader) { ((RowHeader)iContent).Table = table; table.RowHeader = iContent as RowHeader; } else { table.Node.AppendChild(iContent.Node); this.OnWarning(new AODLWarning("Couldn't create IContent from a table node.", tableNode)); } } return table; } catch(Exception ex) { throw new AODLException("Exception while trying to create a Table.", ex); } }
/// <summary> /// Gets the table as HTML. /// </summary> /// <param name="table">The table.</param> /// <returns></returns> public string GetTableAsHtml(Table table) { //TODO: Implement table border algo string html = "<table border=\"1\" "; try { if (table != null) { string style = this.HTMLStyleBuilder.GetTableStyleAsHtml(table.TableStyle); if (style.Length > 0) { html += style; html += ">\n"; } if (table.Rows != null) foreach(Row row in table.Rows) html += this.GetRowAsHtml(row); } } catch(Exception ex) { throw new AODLException("Exception while trying to build a HTML string from a Table object.", ex); } if (!html.Equals("<table border=\"1\" ")) html += "</table>\n"; else html = ""; return html; }
public void DoesNotDuplicateStyles() { TextDocument document = new TextDocument().New(); Assert.AreEqual(0, document.Styles.Count); Table table = new Table(document, "table name", "table style"); Assert.AreEqual(1, document.Styles.Count); table = new Table(document, "table name", "table style"); Assert.AreEqual(1, document.Styles.Count); }
public void DoesNotDuplicateStyles() { TextDocument document = new TextDocument().New(); Table table = new Table(document, "table name", "table style"); Assert.AreEqual(1, document.Styles.Count); table.ColumnCollection.Add(new Column(table, "style name")); Assert.AreEqual(2, document.Styles.Count); table.ColumnCollection.Add(new Column(table, "style name")); Assert.AreEqual(2, document.Styles.Count); }