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.

Wed Oct 25, 2023 5:33 pm

Hi Team ,

I am not able to maintain specific cell's width size .Cell's width size is changing according to the data.

I have added screenshot for you reference

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

Thu Oct 26, 2023 6:07 am

Hi,

Thank you for your inquiry.
For the newly added table in word document, the option shown in the screenshot below will be auto selected, and it will make the settings of cell’s width invalid.
68D8720E-0BC4-4a98-BFEC-AD9D9BCD743D.png

To avoid this issue, you need to add the following three lines of your code:
Code: Select all
table.getTableFormat().isAutoResized(false);
table.getTableFormat().setLayoutType(LayoutType.Fixed);
table.getRows().get(2).getCells().get(2).setCellWidth(500,CellWidthType.Point);

I put the complete code below for your referenece:
Code: Select all
 
         //create a document and load file
        Document document = new Document();
        document.loadFromFile("data/test.docx");
 
        //get the first table
        Section section = document.getSections().get(0);
        Table table = section.getTables().get(0);
       
        table.getTableFormat().isAutoResized(false);
        table.getTableFormat().setLayoutType(LayoutType.Fixed);
        table.getRows().get(2).getCells().get(2).setCellWidth(1000,CellWidthType.Point);

        //save the file
        document.saveToFile("output/outputFile6.docx", FileFormat.Docx);

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

Mon Oct 30, 2023 6:17 am

Hi Team

I have written code to add picture .I do not want space before adding picture so I added top margin value 0.Still I am getting space before picture .Please let us know how to remove top margin space

section.getPageSetup().getMargins().setTop(0);
paragraph = section.addParagraph();
addHomePageImages(System.getProperty("user.dir")+"/Resources/pddImage.jpg");

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

Mon Oct 30, 2023 7:49 am

Hi,

Thank you for your inquiry.
I can achieve your expected results through the latest commercial version of Spire.Office for Java 8.10.2
I put the complete code below for your referenece:
Code: Select all
// Create a new Document object
Document document = new Document();

// Add a new Section to the Document
Section section = document.addSection();

// Set the top margin of the Section to 0
section.getPageSetup().getMargins().setTop(0);

// Set the left margin of the Section to 0
section.getPageSetup().getMargins().setLeft(0);

// Add a new Paragraph to the Section
Paragraph paragraph = section.addParagraph();

// Create a new DocPicture object and pass in the Document
DocPicture picture = new DocPicture(document);

// Load an image from the specified file path into the DocPicture
picture.loadImage("data/1.png");

// Set the width of the DocPicture to 75 units
picture.setWidth(75);

// Set the height of the DocPicture to 90 units
picture.setHeight(90);

// Insert the DocPicture at index 0 in the list of child objects of the Paragraph
paragraph.getChildObjects().insert(0, picture);

// Save the Document to a file with the specified file path and format
document.saveToFile("output/outputFile7.docx", FileFormat.Docx);

If the issue still exists,please offer the following informations to help us do further investigation. Thank you in advance.
1)Your input test file and picture, you can attach here or send it to us via email ([email protected]).
2) Your full test code that can reproduce your issue.

Sincerely,
Ula
E-iceblue support team
User avatar

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

Return to Spire.Doc

cron