Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I created one word document in my vb.net application. but now i need to change the background color of the document from white to any other color for example black.

Can anybody help me out with this issue?
Thanks in advance
Posted

Hi, I haven't had any experience with word documents however I do know that a Word document has an XML file integrated into the file.

Therefore I examined a random .doc file and this is what defines the background.

In the XML inside the root element <w:wordDocument> there should be an element called <bgPict> and within that element resides a line

<w:background w:bgcolor="red"/> if your background is e.g. RED

or

<w:background w:bgcolor="#3BC54B"/> if your background is e.g. SOME GREEN SHADE

However if your file has a default background color (white) the <bgPict> element doesn't exist therefore you can create one.

As I said I have not had any experience whit .doc or .docx files, so if this is of any help I'll be glad to have helped.
 
Share this answer
 
Comments
Weepre 5-Jul-16 9:17am    
That is true for only newer DOCX file format, working with an older .doc format in .net is a bit hard (its pure binary). Nevertheless there are some approaches that can utilise both formats, like this .net library for word processing:

Dim document = DocumentModel.Load("Sample.docx")
document.Sections(0).PageSetup.PageColor = Color.Black

You can refer to this sample for creating a word document in vb.net.
hello all entourage

How to be created word in vb.net so that disabled save command

tanks :-O
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900