private void ExprtWord(object sender, RoutedEventArgs e)
        {
            //initial data source
            listStu      = exportStu.getStuData();
            dataRowCount = listStu.Count + 1;
            string path;

            //creat document、settion and table
            Spire.Doc.Section stuInfoSection = wordDocument.AddSection();
            Spire.Doc.Table   stuTable       = stuInfoSection.AddTable(true);
            stuTable.ResetCells(dataRowCount, columeCount);

            //set header
            Spire.Doc.TableRow row = stuTable.Rows[0];//initial TableRow
            row.IsHeader = true;
            for (int i = 0; i < columeCount; i++)
            {
                para = row.Cells[i].AddParagraph();
                TR   = para.AppendText(strHeader[i]);
            }

            //fill data
            for (int i = 1; i < dataRowCount; i++)
            {
                for (int j = 0; j < columeCount; j++)
                {
                    para = stuTable.Rows[i].Cells[j].AddParagraph();
                    TR   = para.AppendText(listStu[i - 1].GetValue(listStu[i - 1].propertyIndex[j]));
                }
            }

            //

            //save file
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter = "Word Documents(*.docx)|*.docx";
            var res = saveFileDialog.ShowDialog();

            if (res != true)
            {
                return;
            }
            path = saveFileDialog.FileName;
            MessageBox.Show(path);

            wordDocument.SaveToFile(@path, FileFormat.Docx);
            wordDocument.Close();
        }
示例#2
0
        public static void saveNode(Spire.Doc.Document doc, MyNode myNode, int depth)
        {
            if (depth != 1)
            {
                //不保存最大的节点
                Spire.Doc.Documents.Paragraph paraInserted = doc.Sections[0].AddParagraph();
                Spire.Doc.Fields.TextRange    textRange1   = paraInserted.AppendText(myNode.Content + "");
                paraInserted.ApplyStyle(numberToBuitinStyle[depth - 1]);
            }

            for (int i = 0; i < myNode.Child.Count; i++)
            {
                saveNode(doc, myNode.Child[i], depth + 1);
            }
        }
示例#3
0
 public Break(IDocument doc, Spire.Doc.Documents.BreakType breakType) : base((Document)doc)
 {
     this.class442_0  = new Class442();
     this.breakType_0 = breakType;
     this.textRange_0 = new Spire.Doc.Fields.TextRange(doc);
 }
示例#4
0
        public void Export(DataGridView dataGrid, string filename)
        {
            Spire.Doc.Document document = new Spire.Doc.Document();
            Spire.Doc.Section  section  = document.AddSection();
            section.PageSetup.Orientation = Spire.Doc.Documents.PageOrientation.Landscape;

            AddHeaderTitle(section);

            Spire.Doc.Table table       = section.AddTable(true);
            String[]        header      = { "ID", "Full Name", "Date of birth", "Gender", "Phone", "Email", "Position" };
            int             RowCount    = dataGrid.Rows.Count;
            int             ColumnCount = dataGrid.Columns.Count;

            String[][] data = new String[RowCount][];
            for (int i = 0; i < RowCount; i++)
            {
                data[i] = new String[ColumnCount];
            }

            //add rows
            for (int c = 0; c < ColumnCount; c++)
            {
                for (int r = 0; r < RowCount; r++)
                {
                    if (dataGrid.Rows[r].Cells[c].Value.GetType() == typeof(DateTime))
                    {
                        data[r][c] = ((DateTime)dataGrid.Rows[r].Cells[c].Value).ToString("dd/MM/yyyy");
                    }
                    else
                    {
                        data[r][c] = dataGrid.Rows[r].Cells[c].Value.ToString();
                    }
                }
            }

            table.ResetCells(data.Length + 1, header.Length);

            TableRow FRow = table.Rows[0];

            FRow.IsHeader = false;
            FRow.Height   = 23;
            //FRow.RowFormat.BackColor = Color.AliceBlue;
            for (int i = 0; i < header.Length; i++)
            {
                //Cell Alignment
                Spire.Doc.Documents.Paragraph p = FRow.Cells[i].AddParagraph();
                FRow.Cells[i].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
                p.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center;
                //Data Format
                Spire.Doc.Fields.TextRange TR = p.AppendText(header[i]);
                TR.CharacterFormat.FontName  = "Calibri";
                TR.CharacterFormat.FontSize  = 14;
                TR.CharacterFormat.TextColor = Color.Black;
                TR.CharacterFormat.Bold      = true;
            }

            //Data Row
            for (int r = 0; r < data.Length; r++)
            {
                TableRow DataRow = table.Rows[r + 1];

                //Row Height
                DataRow.Height = 20;

                //C Represents Column.
                for (int c = 0; c < data[r].Length; c++)
                {
                    //Cell Alignment
                    DataRow.Cells[c].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
                    //Fill Data in Rows
                    Spire.Doc.Documents.Paragraph p2  = DataRow.Cells[c].AddParagraph();
                    Spire.Doc.Fields.TextRange    TR2 = p2.AppendText(data[r][c]);
                    //Format Cells
                    p2.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center;
                    TR2.CharacterFormat.FontName  = "Calibri";
                    TR2.CharacterFormat.FontSize  = 12;
                    TR2.CharacterFormat.TextColor = Color.Black;
                }
            }

            //Save and Launch
            document.SaveToFile(filename);
            MessageBox.Show("Document Created Successfully!", "Export File", MessageBoxButtons.OK, MessageBoxIcon.Information);
            document.Close();
        }