Hi,
I am creating a word-document using this approach (only a stub of beginning included):
Private Sub CreateWordReport() Me.UltraStatusBar.Text = "" Dim docWriter As WordDocumentWriter = Nothing Try docWriter = WordDocumentWriter.Create("c:\testfolder\" & CType(Me.JournalYearToolStripTextBox.Text, String) & "-" & _ CType(Me.JournalNoToolStripTextBox.Text, String) & ".docx") Catch ex As Exception Select Case ex.HResult Case -2147024864 Me.UltraStatusBar.Text = "Feil oppstod ved opprettelse av dokumentet. Vennligst lukk evnt. åpne svarbrev på samme sak." Exit Sub
End Select
End Try
docWriter.StartDocument() docWriter.DocumentProperties.LatinCulture = "no-bm"
.....................
The code I have written works fine, but there is two things that I struggle with:
1. I am not able to specify that I want the ".docx" to be a "A4"-document instead of a "letter" (which seems to be default).
2. In MS word my default language is "Norwegian - bokmal", but in documents created this way the language setting is always reverted to english. I have tried to use the following line: 'docWriter.DocumentProperties.LatinCulture = "no-bm"', but this does not help.
Regards
Kai
Hello ,
Paper size if a word page is defined by PageSize property of the SectionProperties to which this page belongs (in most cases you should apply this to the “FinalSectionProperties”). Also you should note that Word works with inches and size is in “pixels”(I don’t pretend that the formula used for conversion is absolutely accurate) So here is a simple code snipped:
WordDocumentWriter word = WordDocumentWriter.Create("test.docx"); word.StartDocument(); word.FinalSectionProperties.PageSize = GetSize(PaperKind.A4); word.EndDocument(true);
Process.Start("test.docx");
private SizeF? GetSize(PaperKind paperKind) {
PrinterSettings settings = new PrinterSettings(); PaperSize size = settings.PaperSizes.Cast<PaperSize>().FirstOrDefault( p => p.Kind == paperKind); if(size != null) return new SizeF(toInch(size.Width), toInch(size.Height)); else throw new Exception(); }
private float toInch(float pixels) { return pixels * 71f / 98f; }
I hope that this will helps you.
Thanks, Hristo,
I will try it out. I have not been able yet, as I have run into some severe assembly version trouble after I updated to 14.2.
Can you please also give me some help on my issue regarding languagesettings which I mentioned in my first post.
Best wishes,