Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Thu Nov 16, 2023 6:01 am

Hi Team ,

Is it possible to add our own contents in Authors section[in file's properties] .Please check the attached file for your reference.

Thanks in advance

pr20080798
 
Posts: 159
Joined: Wed Jan 20, 2021 1:15 pm

Thu Nov 16, 2023 7:55 am

Hi,

Thank you for your inquiry.
I put the complete code below for your reference.
Code: Select all
 
            // Create a new document object
            Document doc = new Document();

            // Add a section to the document
            Spire.Doc.Section section = doc.AddSection();

            // Get the built-in document properties
            BuiltinDocumentProperties builtinProperties = doc.BuiltinDocumentProperties;

            // Set the author property of the built-in document properties
            builtinProperties.Author = "Spire.Doc";

            // Save the document to a file
            doc.SaveToFile(@"Set_Properties.docx");

You can also refer to the link(https://www.e-iceblue.com/Tutorials/Spire.Doc/Spire.Doc-Program-Guide/Document-Operation/How-to-set-Word-Document-Properties.html) to help you solve the problem.
If you have any issue just feel free to contact us.

Sincerely,
Ula
E-iceblue support team
User avatar

Ula.wang
 
Posts: 282
Joined: Mon Aug 07, 2023 1:38 am

Fri Nov 17, 2023 9:12 am

Thank you Ula for your response.


I have created a table with empty cells ,if I add data in empty cell ,default style will be "Times New Roman" and font size "12".Please let me know how to change the default style.



Thanks in advance

pr20080798
 
Posts: 159
Joined: Wed Jan 20, 2021 1:15 pm

Fri Nov 17, 2023 10:02 am

Hi,

Thank you for your inquiry.
I put the complete code below for your reference:
Code: Select all
            // Create a new document object
            Document doc = new Document();

            // Add a section to the document
            Section section = doc.AddSection();

            // Add a table to the section with merged cells
            Table table = section.AddTable(true);

            // Reset the cells of the table starting from row 1 and column 2
            table.ResetCells(1, 2);

            // Add a paragraph with text "product" to the first cell in the first row and set its format
            TextRange range = table[0, 0].AddParagraph().AppendText("product");
            range.CharacterFormat.FontName = "Arial";
            range.CharacterFormat.FontSize = 10;
            range.CharacterFormat.TextColor = Color.Teal;
            range.CharacterFormat.Bold = true;

            // Add a paragraph with text "price" to the second cell in the first row and set its format
            range = table[0, 1].AddParagraph().AppendText("price");
            range.CharacterFormat.FontName = "Calibri";
            range.CharacterFormat.FontSize = 5;
            range.CharacterFormat.TextColor = Color.Teal;
            range.CharacterFormat.Bold = true;

            // Save the document to a file named "Table.docx" in Docx format
            doc.SaveToFile("Table.docx", FileFormat.Docx);

You can also refer to the link(https://www.e-iceblue.com/Tutorials/Spi ... B.NET.html) to help you solve the problem.
If you have any issue just feel free to contact us.

Sincerely,
Ula
E-iceblue support team
User avatar

Ula.wang
 
Posts: 282
Joined: Mon Aug 07, 2023 1:38 am

Fri Nov 17, 2023 12:03 pm

Thank you Ula.

This is not my requirement .I will add data in empty cell after generating the Docx file[while creating table I will not add data in the cell] .Please go through the attched screenshot
Last edited by pr20080798 on Mon Nov 20, 2023 4:14 am, edited 1 time in total.

pr20080798
 
Posts: 159
Joined: Wed Jan 20, 2021 1:15 pm

Mon Nov 20, 2023 3:25 am

Hi,

Thank you for your reply,
Here I have uploaded my code and input document for your reference. If there are any misunderstandings, please feel free to write to back.
Code: Select all
        // Create a new document object
        Document document = new Document();

        // Load the content of the "data/table.docx" file into the document
        document.loadFromFile("data/table.docx");

        // Get the first section of the document
        Section section = document.getSections().get(0);

        // Get the first table in the section
        Table table = section.getTables().get(0);

        // Create a new paragraph style object
        ParagraphStyle style = new ParagraphStyle(document);

        // Set the name of the style to "TableStyle"
        style.setName("TableStyle");

        // Set the font name and size for the style
        style.getCharacterFormat().setFontName("Calibri");
        style.getCharacterFormat().setFontSize(25);

        // Add the style to the document's styles
        document.getStyles().add(style);

        // Iterate through each row in the table
        for (int i = 0; i < table.getRows().getCount(); i++) {
            // Get the current row
            TableRow row = table.getRows().get(i);

            // Iterate through each cell in the row
            for (int j = 0; j < row.getCells().getCount(); j++) {
                // Get the current cell
                TableCell cell = row.getCells().get(j);

                // Check if the text in the first paragraph of the cell is empty
                if (cell.getParagraphs().get(0).getText() == "") {
                    // Apply the "TableStyle" to the cell by setting its paragraph's style to "TableStyle"
                    table.get(i, j).getParagraphs().get(0).applyStyle("TableStyle");
                }
            }
        }
        // Save the modified document to a new file named "output/result.docx" with the Docx_2013 format
        document.saveToFile("output/result.docx", FileFormat.Docx_2013);

table.zip


Sincerely,
Ula
E-iceblue support team
User avatar

Ula.wang
 
Posts: 282
Joined: Mon Aug 07, 2023 1:38 am

Tue Nov 21, 2023 1:30 pm

Hi Team


I have written below mentioned code to add headings

ListStyle listStyle = new ListStyle(spireDocument, ListType.Numbered);
listStyle.setName("nestedStyle");
listStyle.getLevels().get(0).setPatternType(ListPatternType.Arabic);
listStyle.getLevels().get(0).setTextPosition(20);
listStyle.getLevels().get(0).getCharacterFormat().setFontName("Open Sans (Headings)");
listStyle.getLevels().get(0).getCharacterFormat().setTextColor(Color.decode("#1BA1E2"));

listStyle.getLevels().get(1).setNumberPrefix("\u0000.");
listStyle.getLevels().get(1).setPatternType(ListPatternType.Arabic);
listStyle.getLevels().get(1).getCharacterFormat().setTextColor(Color.decode("#0E81B8"));
listStyle.getLevels().get(1).getCharacterFormat().setItalic(false);
listStyle.getLevels().get(1).setTextPosition(20);
listStyle.getLevels().get(1).getCharacterFormat().setFontName("Open Sans (Headings)");
listStyle.getLevels().get(1).getCharacterFormat().setFontSize(18);

listStyle.getLevels().get(2).setNumberPrefix("\u0000.\u0001.");
listStyle.getLevels().get(2).setPatternType(ListPatternType.Arabic);
listStyle.getLevels().get(2).getCharacterFormat().setTextColor(Color.decode("#607A7E"));
listStyle.getLevels().get(2).getCharacterFormat().setFontName("Open Sans (Headings)");
listStyle.getLevels().get(2).setTextPosition(20);
spireDocument.getListStyles().add(listStyle);

paragraph = section.addParagraph();
ParagraphStyle heading1Style = (ParagraphStyle) Style.createBuiltinStyle(BuiltinStyle.Heading_1, spireDocument);
heading1Style.getCharacterFormat().setFontSize(fontSize);
heading1Style.getCharacterFormat().setFontName("Open Sans (Headings)");
heading1Style.getCharacterFormat().setBold(false);
spireDocument.getStyles().add(heading1Style);

ParagraphStyle heading2Style = (ParagraphStyle) Style.createBuiltinStyle(BuiltinStyle.Heading_2, spireDocument);
heading2Style.getParagraphFormat().setLeftIndent(60);
heading2Style.getCharacterFormat().setFontSize(18);
spireDocument.getStyles().add(heading2Style);

ParagraphStyle heading3Style = (ParagraphStyle) Style.createBuiltinStyle(BuiltinStyle.Heading_3, spireDocument);
heading3Style.getCharacterFormat().setFontSize(fontSize);
heading3Style.getCharacterFormat().setFontName("Open Sans (Headings)");
heading3Style.getCharacterFormat().setTextColor(Color.decode("#607A7E"));
heading3Style.getCharacterFormat().setBold(true);
spireDocument.getStyles().add(heading3Style);

Issue : There is a huge gap between heading number and heading name ,What is wrong with my code .Please let me know how to remove the space ,I have attached file for your reference.
My point of view is Because of last dot in heading number(Ex 2.2.1. , 2.4. ) I am getting space between heading number and
name. Please let me know how to remove last dot in heading number(ex : 2.2.1 , 2.4 )

pr20080798
 
Posts: 159
Joined: Wed Jan 20, 2021 1:15 pm

Wed Nov 22, 2023 8:09 am

Hi,

Thank you for your inquiry.
By using the following code, you can set the nothing between the list symbol and the title name, achieving a compact layout between the list symbol and the title name.
Code: Select all
  listStyle.getLevels().get(0).setFollowCharacter(FollowCharacterType.Nothing);

If you have any issue just feel free to contact us.

Sincerely,
Ula
E-iceblue support team
User avatar

Ula.wang
 
Posts: 282
Joined: Mon Aug 07, 2023 1:38 am

Wed Nov 22, 2023 9:40 am

Thank you Ula


Is it possible to remove last dot from heading number ?(2.3.2. -> 2.3.2)

pr20080798
 
Posts: 159
Joined: Wed Jan 20, 2021 1:15 pm

Thu Nov 23, 2023 1:38 am

Hi,

Thank you for your more inquiry.
The effect of removing the last dot can be achieved through the following code:
Code: Select all
// Get the list style's level list and set the first level's suffix to an empty string
        listStyle.getLevels().get(0).setNumberSufix("");

If you have any issue just feel free to contact us.

Sincerely,
Ula
E-iceblue support team
User avatar

Ula.wang
 
Posts: 282
Joined: Mon Aug 07, 2023 1:38 am

Thu Nov 23, 2023 10:29 am

Thank you Ula ,

Please let me know how to add space between Header Number and header name in Table of Contents.

Thanks in advance

pr20080798
 
Posts: 159
Joined: Wed Jan 20, 2021 1:15 pm

Fri Nov 24, 2023 8:38 am

Hi,

Thank you for your more inquiry.
The effect of add space between header number and header name in table of contents can be achieved through the following code:
Code: Select all
 listStyle.getLevels().get(0).setFollowCharacter(FollowCharacterType.Space);

If you have any issue, just feel free to contact us.

Sincerely,
Ula
E-iceblue support team
User avatar

Ula.wang
 
Posts: 282
Joined: Mon Aug 07, 2023 1:38 am

Return to Spire.Doc