I am using the following example code and would like to add in the body of the word document a line chart. my datasource is an array. An example would be great to get me started. I could only find examples inside of Excel.
Imports Infragistics.Documents.Word ' Create a new instance of the WordDocumentWriter class using the ' static 'Create' method. ' This instance must be closed once content is written into Word. Dim docWriter As WordDocumentWriter = WordDocumentWriter.Create("C:\TestWordDoc.docx") ' Use inches as the unit of measure docWriter.Unit = UnitOfMeasurement.Inch ' Create a font, which we can reuse in content creation Dim font As Infragistics.Documents.Word.Font = docWriter.CreateFont() 'Start the document...note that each call to StartDocument must 'be balanced with a corresponding call to EndDocument. docWriter.StartDocument() 'Start a paragraph docWriter.StartParagraph() ' Add a text run for the title, bolded and a little bigger font.Bold = True font.Size = 0.23F font.Underline = Underline.[Double] font.UnderlineColor = Color.Blue font.Effects.Capitalization = Capitalization.CapsOn docWriter.AddTextRun("Paragraphs and Topic Sentences", font) 'End the paragraph docWriter.EndParagraph() ' Paragraph Properties Dim paraformat As ParagraphProperties = docWriter.CreateParagraphProperties() paraformat.Alignment = ParagraphAlignment.Right ' Start another Paragraph ' and apply the ParagraphProperties Object docWriter.StartParagraph(paraformat) docWriter.AddNewLine() ' Reset font, and apply different font settings for this paragraph. font.Reset() font.Italic = True font.ForeColor = Color.Blue font.Effects.TextEffect = FontTextEffect.EngravingOn docWriter.AddTextRun("A paragraph is a series of sentences that are organized and coherent, and are all related to a single topic. Almost every piece of writing you do that is longer than a few sentences should be organized into paragraphs. This is because paragraphs show a reader where the subdivisions of an essay begin and end, and thus help the reader see the organization of the essay and grasp its main points.", font) ' End the paragraph docWriter.EndParagraph() ' Set page attributes Dim secProperties As SectionProperties = docWriter.CreateSectionProperties() secProperties.PageSize = New SizeF(7, 5) secProperties.PageOrientation = PageOrientation.Landscape ' Applies the section properties(Page Size and Orientation) for the above added paragraphs docWriter.DefineSection(secProperties) 'Add an Empty paragraph docWriter.AddEmptyParagraph() docWriter.StartParagraph() font.Reset() font.ForeColor = Color.Red docWriter.AddTextRun("The above page is defined by the Section Properties object. The size of the page is set to 7x5 inches and the Orientation is set to Landscape.", font) docWriter.EndParagraph() ' End the Document docWriter.EndDocument() ' Close the writer docWriter.Close()
Hello Colin,
I have been investigating into this behavior you are looking to achieve, and while you are correct that there are examples for this in Excel, this functionality unfortunately does not currently exist for the Word Library.
The best thing that I can recommend in this case is to put together an UltraDataChart and save it to an Image and then you can add that Image to your Word Document. I am placing a pair of links to our documentation below that show, with code snippets, how to do the below:
Save UltraDataChart to an Image: https://ko.infragistics.com/help/winforms/datachart-saving-a-chart-to-an-image
Place Image in Word Document: https://ko.infragistics.com/help/winforms/word-add-images-to-word-document
If you would like to see the chart adapter functionality that exists in the Excel Library added to the Word Library, I would recommend suggesting a new product idea for this at our Windows Forms Ideas Site, here. This will place you in direct communication with our product management teams who plan and prioritize upcoming features and development based on community and user feedback.
Please let me know if you have any other questions or concerns on this matter.
That worked great and the suggestions helps. How can I resize the image so that it fits correctly on my document?
In order to resize the image, I would recommend using the overload of the WordDocumentWriter.AddAnchoredPicture method that takes an AnchoredPicture object rather than the Image itself. The AnchoredPicture object lets you set the Image as well as the Size that you wish that image to be rendered, and this should allow you to resize the image to your liking.
Can you provide some example code of this?
I am attaching a sample project to demonstrate the above. I hope it helps you.
ChartToWordDocument.zip