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,
Have you tried ComplexScriptCulture, LatainCulture and EastAsiaCulture
http://help.infragistics.com/Help/Doc/WinForms/2014.2/CLR4.0/html/Infragistics4.Documents.IO.v14.2~Infragistics.Documents.Word.WordDocumentProperties~ComplexScriptCulture.html
http://help.infragistics.com/Help/Doc/WinForms/2014.2/CLR4.0/html/Infragistics4.Documents.IO.v14.2~Infragistics.Documents.Word.WordDocumentProperties~LatinCulture.html http://help.infragistics.com/Help/Doc/WinForms/2014.2/CLR4.0/html/Infragistics4.Documents.IO.v14.2~Infragistics.Documents.Word.WordDocumentProperties~EastAsiaCulture.html
I ma waiting for your feedback.
Update:
I found a table which says "nb-NO" (for Norwegian bokmal), and now things are OK.
Thanks again
Hello,
I have tried:
docWriter.DocumentProperties.LatinCulture = "no-bm", but it has no effect.
There is no samples on how to use this setting, so I guess I am doing something wrong.
Also, There is no table of valid "LatinCulture" strings so I guess "no-bm" is not the correct way to specify "Norwegian bokmal"?
The PageSize problem has been solved with the help of your last post.
Regards,
Kai-Inge