Using CSS with ASPOS.WORD

Hi,
I am indulge in a project which involves creating a resume in doc form from VB.NET application and i am using ASPOS.WORD for it. In order to do the appropriate formatting, i want to know whether it is possible to incorporate CSS with it, as doing so will make the work much simpler other wise its very bulky ane tedious to every time write the document builder specifications.
Kindly let me know about it at the earliest. Its better if the methods are also stated.
Thank you.

Hi
Thanks for your request. I think the easiest way to achieve what you need is: create a template document, where you should define styles that should be used. Then you will need just set an appropriate style for Paragraph or Run to set its formatting.
Of course, you can use HTML formatting and CSS, but I think using MS Word styles is a better way. If you prefer using CSS, you should note: Aspose.Words should know full path where to find CSS file. When you just open HTML document from file, there should not be any problems. But when you use InsertHtml, there can be problems with relative paths. So, you should specify absolute path like shown below:

<html>
<head>
    <link type='text/css' rel='Stylesheet' href='file:///c:/temp/test.css' />
</head>
<body>
    <p><span class='red'>This should be red text.</span></p>
</body>
</html>

Also, you can specify baseurl, like shown below:

<html>
<head>
    <base href='file:///c:/temp/' />
    <link type='text/css' rel='Stylesheet' href='test.css' />
</head>
<body>
    <p><span class='red'>This should be red text.</span></p>
</body>
</html>

In addition, one more disadvantage of using CSS is that Aspose.Words does not support inheriting formatting from parent elements in HTML.
Hope this helps.
Best regards,

Hi,
Thanks for your reply.
Actually i have to pickup data from a database using VB. NET application and write the contents in a doc file giving the user the option to download the doc file from the application.
What i want is that the doc should be in proper formatted order when it gets downloaded to a user’s system. I am trying to write contents on the doc file using ASPOS.WORD, but since a large data is to be wriiten on the doc file and for ech paragraph specifying font size, color, alignment etc each time will lead to writing large volume of ASPOS.WORD codes.
Kindly let me know (If possible through an example in VB) how to do so easily using CSS or other technique so that the tye contents get written in the doc in proper order and format without specifying parameters every time.
Pla reply at the earliest.
Thank you.

Hi
Thanks for your request. As I suggested earlier, you can easily achieve this by using styles in MS Word document. You should create a document where you define styles you need and then just use this document as a template for your documents. For example you can use code like the following to set styles:

// open tempalte where you styles are defined.
Document doc = new Document(@"Test001\in.doc");
// DocumentBuilder will help us to build a document.
DocumentBuilder builder = new DocumentBuilder(doc);
// Use styls to insert content with diferent formating.
builder.ParagraphFormat.Style = doc.Styles["Heading 1"];
builder.Writeln("This is heading 1 text");
// Save way insert few more paragraphs with diferent styles.
builder.ParagraphFormat.Style = doc.Styles["Heading 2"];
builder.Writeln("This is heading 2 text");
builder.ParagraphFormat.Style = doc.Styles["Heading 3"];
builder.Writeln("This is heading 3 text");
builder.ParagraphFormat.Style = doc.Styles["Heading 4"];
builder.Writeln("This is heading 4 text");
// Save output.
doc.Save(@"Test001\out.doc");

As you can see, using styles will significantly simplify your code.
Best regards,

Hi,
Thanks for your response. I understand what you are trying to convey but the problem is that if the word styles are not present on the user’s computer than all the formatting gets void.
I tried to insert the image using Aspose.word which worked fine, then tried to write the content in the word file using the general ASP.Net method (without uing aspos.word properties) for writing to the word document, but its not working.
Kindly let me know whether its possible to do so. If so kindly specify the procedure and if not let me know any other method.
Awaiting your response.
Thank you.

Hi
Thanks for your request. Actually styles should not be present on the user’s computer, styles should be defined in the document that you are using as a template, i.e. in your input document. Please see my code.
Unfortunately, it is not quite clear for me how you would like to write content in a Word document without using Aspose.Words. Could you please clarify and provide a simple code?
Best regards,