コード例 #1
0
        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);
            }
        }
コード例 #2
0
        public void CreateTableFormatedText()
        {
            //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();
            //cell.OfficeValueType					= "string";
            //Set full border
            //cell.CellStyle.CellProperties.Border	= Border.NormalSolid;
            //Add a paragraph to this cell
            Paragraph paragraph = ParagraphBuilder.CreateSpreadsheetParagraph(
                spreadsheetDocument);
            //Create some Formated text
            FormatedText fText = new FormatedText(spreadsheetDocument, "T1", "Some Text");

            //fText.TextStyle.TextProperties.Bold		 = "bold";
            fText.TextStyle.TextProperties.Underline = LineStyles.dotted;
            //Add formated text
            paragraph.TextContent.Add(fText);
            //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 + "formated.ods");
        }
コード例 #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="filePath"></param>
 public OpenDocumentServices(String filePath)
 {
     this.filePath = filePath;
     this.document = new SpreadsheetDocument();
     document.New();
     //  document.SaveTo(filePath);
     //  this.document.Load(filePath);
     this.table = new Table(document, "Foglio di lavoro", "");
     this.document.TableCollection.Add(table);
     this.title = "";
     currentRow = 0;
 }
コード例 #4
0
        public void SpreadSheetFormsTest()
        {
            //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 = new Cell(spreadsheetDocument, "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.Rows.Add(new Row(table, "Standard"));
            table.Rows.Add(new Row(table, "Standard"));
            table.Rows.Add(new Row(table, "Standard"));
            table.InsertCellAt(3, 2, cell);
            //Insert table into the spreadsheet document

            ODFForm main_form = new ODFForm(spreadsheetDocument, "mainform");

            main_form.Method = Method.Get;
            ODFButton butt = new ODFButton(main_form, cell.Content, "butt", "0cm", "0cm", "15mm", "8mm");

            butt.Label = "test :)";
            main_form.Controls.Add(butt);
            spreadsheetDocument.TableCollection.Add(table);
            table.Forms.Add(main_form);

            spreadsheetDocument.SaveTo(AARunMeFirstAndOnce.outPutFolder + "spreadsheet_forms.ods");

            SpreadsheetDocument spreadsheetDocument2 = new SpreadsheetDocument();

            spreadsheetDocument2.Load(AARunMeFirstAndOnce.outPutFolder + "spreadsheet_forms.ods");
            ODFButton b = spreadsheetDocument2.TableCollection[0].FindControlById("butt") as ODFButton;

            Assert.IsNotNull(b);
            b.Label = "it works!";
            spreadsheetDocument2.SaveTo(AARunMeFirstAndOnce.outPutFolder + "spreadsheet_forms2.ods");
        }
コード例 #5
0
 public void CreateNewSpreadsheet()
 {
     _spreadsheetDocument1 = new SpreadsheetDocument();
     _spreadsheetDocument1.New();
     Assert.IsNotNull(_spreadsheetDocument1.DocumentConfigurations2);
     Assert.IsNotNull(_spreadsheetDocument1.DocumentManifest);
     Assert.IsNotNull(_spreadsheetDocument1.DocumentPictures);
     Assert.IsNotNull(_spreadsheetDocument1.DocumentThumbnails);
     Assert.IsNotNull(_spreadsheetDocument1.DocumentSetting);
     Assert.IsNotNull(_spreadsheetDocument1.DocumentStyles);
     Assert.IsNotNull(_spreadsheetDocument1.TableCollection);
     //_spreadsheetDocument1.Save(AARunMeFirstAndOnce.outPutFolder+"blank.ods");
     //Assert.IsTrue(File.Exists(AARunMeFirstAndOnce.outPutFolder+"blank.ods"));
 }
コード例 #6
0
        public void NewBasicChartThenSetTitle()
        {
            const string        expected = "Basic Chart";
            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      basicChart = ChartBuilder.CreateChart(table, ChartTypes.line, "A4:F8");
            ChartTitle ct         = new ChartTitle(basicChart);

            //ct.InitTitle();
            ct.SetTitle(expected);
            Assert.AreEqual(expected, ((Paragraph)ct.Content[0]).TextContent[0].Text);
            basicChart.ChartTitle = ct;
            IContent chartTitleContent = basicChart.Content.Find(o => o is ChartTitle);

            if (chartTitleContent == null)
            {
                foreach (IContent iContent in basicChart.Content)
                {
                    if (iContent is ChartTitle)
                    {
                        chartTitleContent = iContent;
                    }
                }
            }
            Assert.AreEqual(expected, ((Paragraph)((ChartTitle)chartTitleContent).Content[0]).TextContent[0].Text);
            table.InsertChartAt("H2", basicChart);
            doc.TableCollection.Add(table);
            using (IPackageWriter writer = new OnDiskPackageWriter())
            {
                doc.Save(Path.Combine(AARunMeFirstAndOnce.outPutFolder, "BasicChartWithTitlesetafterwards.ods"), new OpenDocumentTextExporter(writer));
            }
        }
コード例 #7
0
        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);
            using (IPackageWriter writer = new OnDiskPackageWriter())
            {
                doc.Save(Path.Combine(AARunMeFirstAndOnce.outPutFolder, @"NewChartOne.ods"), new OpenDocumentTextExporter(writer));
            }
        }
コード例 #8
0
        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);
            }
        }
コード例 #9
0
ファイル: CreateBlank.cs プロジェクト: Manicca/Interiora
        void Supl(int id) //бланк в разрезе по поставщикам, поэтому функция для фильтрации объектов того или иного поставщика
        {
            SpreadsheetDocument spreadsheetDocument = new SpreadsheetDocument();

            spreadsheetDocument.New();
            Table table = new Table(spreadsheetDocument, "First", "tablefirst");

            for (int j = 0; j < countsup; j++)
            {
                Paragraph parag = ParagraphBuilder.CreateSpreadsheetParagraph(spreadsheetDocument);
                var       text  = TextBuilder.BuildTextCollection(spreadsheetDocument, " ");
                Cell      cell  = table.CreateCell();
                parag.TextContent.Add(new SimpleText(spreadsheetDocument, "элемент бд, где поставщик ид=ид"));//И за это тоже выебу и в прямом, и в переносном смысле за такие фразы
                cell.Content.Add(parag);
                table.InsertCellAt(0, 0, cell);
                spreadsheetDocument.TableCollection.Add(table);
                spreadsheetDocument.SaveTo("Matr.ods");
            }
        }
コード例 #10
0
        /// <summary>
        /// Exports the provided report template to an ODS document.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        protected override Stream Export(IGenerationContext context)
        {
            IReportTemplateSection sdet = context.Template.Sections.GetSection(SectionType.Detail);

            SpreadsheetDocument doc = new SpreadsheetDocument();

            doc.New();

            IMultipleRowsProducer producer = sdet.RootElement.FindFirstMultipleRowsProducer();

            if (producer != null)
            {
                Table table = TableBuilder.CreateSpreadsheetTable(doc, "Table", string.Empty);
                doc.Content.Add(table);

                WriteTable(producer, table, context);
            }

            return(CreateStream(doc));
        }
コード例 #11
0
        /// <summary>
        /// Metodo per la generazione di un report ODS
        /// </summary>
        /// <param name="request">Informazioni sul report da produrre</param>
        /// <param name="reports">Report da esportare</param>
        /// <returns>Foglio di calcolo Open Office</returns>
        public FileDocumento GenerateReport(PrintReportRequest request, List <DocsPaVO.Report.Report> reports)
        {
            // Instanziazione del writer ODS e creazione del documento
            SpreadsheetDocument spreadSheetDocument = new SpreadsheetDocument();

            spreadSheetDocument.New();



            // Generazione di un foglio per ogni report
            foreach (var report in reports)
            {
                // Generazione di un foglio con i dati contenuti nel report
                this.AddWorksheet(spreadSheetDocument, report, request.ReportKey);
            }

            // Inizializzazione del file name
            String fileName = String.Format("Report_{0}.ods", DateTime.Now.ToString("dd-MM-yyyy"));

            // Inizializzazione del path del file
            String filePath;

            if (!String.IsNullOrEmpty(DocsPaUtils.Configuration.InitConfigurationKeys.GetValue("0", "BE_TEMP_PATH")))
            {
                filePath = Path.Combine(
                    DocsPaUtils.Configuration.InitConfigurationKeys.GetValue("0", "BE_TEMP_PATH"),
                    String.Format(@"AODF\{0}", Guid.NewGuid()));
            }
            else
            {
                filePath = Path.Combine(
                    Environment.GetFolderPath(Environment.SpecialFolder.InternetCache),
                    String.Format(@"AODF\{0}", Guid.NewGuid()));
            }

            //String filePath = Path.Combine(
            //    Environment.GetFolderPath(Environment.SpecialFolder.InternetCache),
            //    String.Format(@"AODF\{0}", Guid.NewGuid()));

            // Creazione della cartella
            DirectoryInfo dirInfo = Directory.CreateDirectory(filePath);

            // Salvataggio del file Open Document
            spreadSheetDocument.SaveTo(Path.Combine(filePath, fileName));

            // Generazione del risultato dell'export
            FileDocumento document = new FileDocumento();

            using (MemoryStream stream = new MemoryStream(File.ReadAllBytes(Path.Combine(filePath, fileName))))
            {
                document.name        = fileName;
                document.path        = String.Empty;
                document.fullName    = document.name;
                document.contentType = "application/vnd.oasis.opendocument.spreadsheet";
                document.content     = new Byte[stream.Length];

                stream.Read(document.content, 0, document.content.Length);

                stream.Flush();
                stream.Close();
            }

            // Si provano a cancellare File e cartella
            this.DeleteTemporaryData(dirInfo);

            return(document);
        }