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
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
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.
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
Am evaluating the Aspose.words for one of my client, almost all of the feature i have migrated from MS Word library to Aspose.word library. Just one more to go, but am struggling to find the solution for the below:
We have Template document which is in .docx format. Template has a Two column page layout. at run time system would copy paste the content from other document to this Template document. still this steps works fine.
When i open the template page it looks good with 2 column layout.
But we have some logic that should read the last line of First Column & checks whether the text is in specific format, if it is then moves one line down which would automaticaly moves to the next column.
This logic is easily acheivable in Word but i couldn't find any refference in Aspose.words to implement this.
Also i tried to find different option by convering the document to Xml. & found that there is one node called . but this node is visble only when i save the document as xml From Microsoft word. Not occurs if i save the document as xml from Aspose.words.
Please advice me to solve this issue.
Thanks in advance
Gunasekara S
we just have finished integrating a feature into Aspose.Words to open up access to the rendering engine so that each element of the rendered document can be read as it appears as pages, columns, lines, spans etc. This functionality is exactly what you need and will be available in the next version of Aspose.Words which is expected to release in about a week's time. Soon I will be sharing the code snippet to accomplish your requirement.
My name is Nayyer and I am developer evangelist at Aspose.
We have a requirement, in which we need to create dynamic word document and these word documents contains Table, Chart, text and images to be replace/update dynamically. So we decided to create a template and place text holders at dynamic places. To create new document by reading and updating Template we decided to go for OpenXML SDK 2.0.
I am successfully able to replace/update Text/Table and Image content (for place holder tagging we are using Content Controls and we assign a unique tag to each content control.)
I am still trying to figure out, how we will modify the chart data. As far as i know about chart part, it has its own underlying xlx data file, in which it stores the data. So now to update chart part i can think of three different solutions.
1.) Update underlying xlx file by using Open SDK. I am not sure if this can be done or not, but considering its just an xlx file, so i should be able to modify it using Open XML Sdk itself.
2.) Create a chart, convert into image and then replace the image.
3.) I have also read about Custom XML, in which we can bind Content Controls with that XML. So the idea is to create a chart with Custom XML as datasource and then update data xml dynamically.
Any suggestions or Code samples would be appreciated. I am using Open XML SDK 2.0.
I tried with approach1, I modified the underlying xlsx data, but seems it was not sufficient as under Chart.xml -> ChartSpace -> Chart-> PlotArea -> BarChart -> BarChartSeries -> Values, it was saving those numeric values. So i guess i am missing a component, which can read from xlsx and then updates chart accordingly. For now i have manually updated the both xlsx and Values so that it is reflected properly.