This project has moved and is read-only. For the latest updates, please go here.

tag properties

Jul 1, 2010 at 10:58 PM
Edited Jul 2, 2010 at 1:36 PM

in first place.. good job for your library.. works very fine... and i haven't take too much trouble for now...

although there are some properties that aren't recognized.. like font-size and margin in the style="" attribute...
<span style="font-size:24pt">Big Text</span>
and it will be very useful if the <style> tag is parsed and processed in the styles.xml file inside de docx.. like these...
<style type="text/css">
<h1 class="header">Some Header</h1>
<p class="paragraph">Some Paragraph</p>

other thing that will be useful in the future, is to interpret the <input> tag and convert to Structured Document Tag ("sdt") in the .docx

<input type="text" name="username"/>

to <w:sdt>
<w:alias w:val="username" />
<w:text />

if I find another detail i will post it here...
Jul 2, 2010 at 10:34 AM

Hi NioZero,

Interpreting the <input> tag sounds a good idea for me. I can deal with:

  • textbox,
  • textarea (rich text),
  • radio button
  • check box
  • date picker (using non-standard html)
  • drop down
  • buttons are useless
  • do I miss a control?

I have already worked with std forms in the past so I'm not lost with that part of the API :)

Regarding your request about styles, I was expecting someone will ask me that feature one day.
This is very difficult to implement. You known, in CSS, the C stands for Cascading. This means dealing with inheritance and x-path condition (CSS3 selectors).

This represents a huge amount of time to be written and I don't plan to do this for the moment.
In the past, I thought about using a more powerful parser than my regex based engine. I considered using HtmlAgilityPack, this can be a good starting point...

Jul 2, 2010 at 1:44 PM
Edited Jul 2, 2010 at 1:46 PM
hi again onizet...

about the css, i understand the difficulty... because is another language to parse... another ideally feature, but also very difficult to implement, is to convert javascript code into macro code...

about the input... usually the date picker is an <input type="text"> and a div popup with a date picker (like jquery)..
another control may be the image using a <input type="file">....

about the non-standard way to maintain the standard code is to using class properties... jquery for example can apply effects to input tag (and other tags too) only using the class properties (or the ID)... for example
<input type="text" class="datepicker" />

keep the good work...
Jul 2, 2010 at 1:59 PM

I was thinking about using class="datepicker", type="datepicker" and checking an attribute named "datepicker"  :)
Good idea for <input type="file">

Wow converting js to macro code... totally out of scope but a pretty dream

Jul 2, 2010 at 3:18 PM
Edited Jul 2, 2010 at 3:21 PM
haha... yeah... a nice dream...

i was making tests with this generic html file using encapsulated functions to create the document and to save it into disk..

// the _variables are declared privately
public void CreateDocument(String fileName)
	_filePath = fileName;

	if( (_memory = new MemoryStream()) != null )
		if( (_document = WordprocessingDocument.Create(_memory, WordprocessingDocumentType.Document))!=null )
			_package = _document.Package;

			MainDocumentPart mainPart;

			if ( (mainPart = _document.MainDocumentPart) == null)
				mainPart = _document.AddMainDocumentPart();
				new Document(new Body()).Save(mainPart);
			_converter = new HtmlConverter(mainPart);

public void SaveContent(String contentHTML)
	String html = String.Empty;
	html += "<html><head>";
	html += "</head><body>";
	html += contentHTML;
	html += "<body></html>";
	MainDocumentPart mainPart = _document.MainDocumentPart;

	Body body = mainPart.Document.Body;
	var paragraphs = _converter.Parse(html);
	for (int i = 0; i < paragraphs.Count; i++)


	File.WriteAllBytes(filePath, _memory.ToArray());

this works fine, with no crash at least, but the document isn't created correctly... because when i open it with in word appears this window...

I'm checking the xml manually ... if I find some detail i will post it ..
Jul 2, 2010 at 4:00 PM
Edited Jul 2, 2010 at 4:00 PM
using your suggested method to create documents works fine, and well, the results are not the best...

public void CreateAndSave(String fileName,String contentHTML)
	using (MemoryStream generatedDocument = new MemoryStream())
		using (WordprocessingDocument package = WordprocessingDocument.Create(generatedDocument, WordprocessingDocumentType.Document))
			MainDocumentPart mainPart = package.MainDocumentPart;
			if (mainPart == null)
				mainPart = package.AddMainDocumentPart();
				new Document(new Body()).Save(mainPart);

			HtmlConverter converter = new HtmlConverter(mainPart);
			Body body = mainPart.Document.Body;

			var paragraphs = converter.Parse(contentHTML);
			for (int i = 0; i < paragraphs.Count; i++)


		File.WriteAllBytes(fileName, generatedDocument.ToArray());

the problem is that i need to use different methods because i need to use the WordProcessingDocument variable into another things... (for this example I'm not using those functionality)