I'm trying to write C# code to Copy-Paste charts from Excel and use Paste Link in MS Word, because with Excel, when you use Paste Link for the tables, text, charts, etc. I can click update all fields in Word after you change anything in Excel.
I was trying to use OpenXML to add content controls in Word and paste the charts to those spots, like what this blogger does.
http://www.dotblogs.com.tw/angus/archive/2010/05/19/15332.aspx
I added content control of the type "pictures" for each chart and they were successfully pasted in but not as links. Thus when I click "update links now" in Word after Excel data change, the charts in Word stay the same.
Maybe I didn't add the right type of content control? I don't know which type I should use for links.
Could any one point me to some source code or even a software?
Have a look here:
VBA: How to Programmatically Insert an Excel Chart into Word.
C#: Automating Word Tables for Data Insertion and Extraction
The magic does PasteSpecial method and its input parameter: Link set to True ;)
For further information, please see: Link or embed an Excel worksheet
Related
I am working with word and c# . taking the snap shot with my code and saving it in a particular folder (ex.C:\Temp). now i want to save the image to an existing word document.any kind of help with short code sample is highly appreciated .
Will prefer to use Microsoft.Office.Interop.Word;
Of course, the Word object model provides the required methods for inserting an image into the document. To add a picture at the cursor location you just need to call the AddPicture method of the InlineShapes collection and pass in the name of the file.
Application.Selection.InlineShapes.AddPicture(#"C:\SamplePicture.jpg");
See How to: Programmatically Add Pictures and Word Art to Documents for more information.
Also you may consider using the Open XML SDK. Take a look at the following articles in MSDN:
How to: Insert a picture into a word processing document (Open XML SDK)
Adding Images to Documents in Word 2007 by Using the Open XML SDK 2.0 for Microsoft Office
Hello I am looking for a way to open an Excel sheet programmatically and allow the user to be able to select a range of cells. My reasoning behind this is I am currently developing a lot of individual excel upload forms for pulling data in to a database I would like the ability to select the column headers as simply as highlighting the cells through excel and presenting a textbox for each to enter the equivalent DB table column name and store these. So effectively a form to create a form.
Many thanks
Charlie
Please check this article: Opening and Navigating Excel with C#.
There is also a section in MSDN library that completely covers Excel PIA.
There're a data list with hundreds of data items (suppose each item is a customer), and a predefined word document as template, the requirement is - for each data item, fill corresponding data into template fields, and generate a readonly PDF file as result.
Prefered platform is ASP.NET with C#.
I found two solutions:
Change the word document into a PDF form, and use iTextSharp to fill the form fields. But create the PDF form with correct format (font, layout, etc.) is a difficult work, and it needs particular tool and new skill when system user wants to add new template (unless the PDF form is always created by developer).
Add text placeholder in the word file, and the program can read word file, replace text, and convert into PDF. But I'm not sure which components should be used.
I'd like to get some advices on this problem. tks.
Update 20130416:
After some searching & experiments, my conclusion is below:
Client solution: use Microsoft.Office.Interop.Word (Office2007+plugin or Office2012) to read data, convert to pdf, etc. But this method running on server side may be unsafe.
Server solution:
Make PDF form, and use iTextSharp to fill the form fields. The disadvantage has been mentioned above.
Make HTML template, and replace field placeholders, and use iTextSharp+XMLWorker to convert HTML to PDF. The difficulty is create the HTML template manually and optimize the PDF effect.
MS SharePoint Office Automation Service is a server solution based on MS Office, perhaps this method will be easier, but it needs license and SharePoint server cost.
Finally, I chose the HTML template solution for this request. QED.
Another option would be to use Tx Text Control for ASP.NET. They have a
mailmerge feature that allows you to fill data into a word template.
The merged document can easily be saved as a pdf.
For the second option you can use iTextsharp or Aspose which supports the placeholder replacement and generation PDF, it supports creating files based on templates of MSWord and Openoffice which could be usefull for user who do not want to buy MSWord only to create a template.
Another option, you can use nustache templates, fill them with list data and then use xmlworker from ItextSharp to render to pdf.
Using C# & OpenXML, I need to create a document. The document have series of paragraphs created under docs body. I need to make few paragraphs ready-only. To accomplish this the entire document made read-only. Edit permission to few paragraphs are provided using permStart and permEnd tags. The generated document sent to the user.
The user could edit the editable paras, could add lot of information using tables, paragraphs & could format the text using different color, font size, font type. After making these changes user sends the document back to the server, where I need to extract each editable area's text with complete format and structure & store into a database table. Each editable area's text goes to one column of the table. After saving all editable area's text into their corresponding columns, the docx file discarded.
In future when user requests the same document, we need to take the stored content from db and create a document, by recreating the content with all original formatting/structure.
My question is how can we extract the paragraph with all its formatting intact and store into a database table & recreate the content in another document in future request for the same document.
I'm using OpenXML SDK 2.0, MS-Visual Studio 2010, .NET 4.0 and Win7 OS. The user will use Office 2007/2010 to edit the content.
Finally (few months before) I was able to extract editable paragraphs from word document using Eric White's excellent OpenXML PowerTools OpenSource. Have a look at Eric's DocumentBuilder samples to extract paras from doc
because of small documentation i have problems with OpenXml SpreadSheetDocument in C#.
How to make top row with filter?
How to make colors to alternate?
I want to put unicode characters in my SheetData, but when i oppen the excel it gives me an error..
Change the top row color.
Can you say if there are some proper ways to do this, some more documentation than these available on msdn, or post some StyleSheet code?
Sorry for my english.
Thanks.
I think that your question is really about how to create tables in a spreadsheet. Tables are a cool feature of Open XML / Excel 2007 / 2010 that enable you to sort a range of cells by clicking on column headings. Also they are presented with alternative color bands for rows. There are additional features, such as ability to have a total row, and automatic expansion when you insert a row.
I've written a blog post about tables and how to create them: Exploring Table Markup in SpreadsheetML. In addition, I've recorded a 15 minute screen-cast that explores the markup, and shows how to create an Open XML SDK program that converts ordinary cells into a table.
-Eric
I can't give you a silver bullet, unfortunately, but what I did when trying to work out how to build Word Documents with OpenXML was to do the work in Word, then explore the resulting .docx file to see what the effect was.
I've suggest that the same investigative approach may help you with your spreadsheet.