|
|
Aspose word For .NET
-
02-03-2012, 9:25 AM |
-
mp1
-
-
-
Joined on 01-25-2012
-
-
Posts 9
-
-
-
-
-
|
Aspose word For .NET
Hello Sir/Madam,
I am a programmer at AIG. I am looking at this product Aspose word for .Net and seems interesting.
I have a few question before i can buy this product.
1. I am using MS word template and HTML embeded text is in SQL server tables. I want to able to convert/format those fields that have HTML embedded text and put in designed Document template. Is this possible to achieve with Aspose word.net?
2. In MS word document template, I have table with bookmark.. And they have to repeat if there are multiple recs found in Database.. i want to know how can i use asponse to achieve this? For example
Ticket NO Issues No Description
1 1 abc...
1 2 xyz..
Right now i am using mail merge to get the non HTML fields to generate doc file..
Thanks and reply soon
MP
|
|
-
02-03-2012, 10:14 AM |
-
awais.hafeez
-
-
-
Joined on 09-16-2011
-
Lahore, Pakistan
-
Posts 2,195
-
-
-
-
-
|
Hi,
Thank you for considering Aspose.Words.
1. First of all, I would suggest you read the following article on How-to: Execute Simple Mail Merge: Secondly, you can use the following code snippet to be able to insert HTML in merge fields:
Document
doc = new Document(@"c:\test\in.docx");
doc.MailMerge.FieldMergingCallback
= new HandleMergeFields(); doc.MailMerge.Execute( new string[] { "simpleField",
"htmlField" }, new object[] { "value
for simple field", "<table
border='1'><tr><td>cell 1</td><td>cell
2</td></tr><tr><td>cell 3</td><td>cell
4</td></tr></table>" });
doc.Save(@"c:\test\out.docx");
private class HandleMergeFields
: IFieldMergingCallback { void IFieldMergingCallback.FieldMerging(FieldMergingArgs e) { if
(e.FieldName == "htmlField") { //Create
document builder DocumentBuilder
builder = new DocumentBuilder(e.Document); //Move
cursor to field builder.MoveToField(e.Field, true); // Insert
HTML builder.InsertHtml(e.FieldValue.ToString()); // Remove
the string representation of HTML e.Text = string.Empty; } }
void IFieldMergingCallback.ImageFieldMerging(ImageFieldMergingArgs args) { // DO NOTHING } }
2. Please note that, it is by MS WORD design that a Word document must have unique names for bookmarks. You can not insert two bookmarks with the same names. Repeating rows with bookmarks is simply not supported by MS WORD. I think, in your case, the best approach to achieve this is by using Mail Merge with Regions. For more information, please read the following articles:
Please let us know if you need more information, we are always glad to help you.
Best Regards,
Awais Hafeez Support Developer Aspose Sialkot Team Aspose - Your File Format Experts Keep in touch! We're on Twitter and Facebook
|
|
-
02-03-2012, 3:01 PM |
-
mp1
-
-
-
Joined on 01-25-2012
-
-
Posts 9
-
-
-
-
-
|
Re: Aspose word For .NET
(Platform: Microsoft Word)
Thanks for reply.
Right now i am trying to insert HTML fields into word template..
Fields i am getting from sql tables.
the example you showed for HTML field is inserting one field in template
I have many simple mail merge fields and also multiple HTML fields that all together needs to go in document template. Can you give me code snippet to achieve that? if you want i can upload my document template..
Thank you
|
|
-
02-06-2012, 5:52 AM |
-
awais.hafeez
-
-
-
Joined on 09-16-2011
-
Lahore, Pakistan
-
Posts 2,195
-
-
-
-
-
|
Hi,
Thanks for your inquiry and sorry for the delayed response. In this case you can make use of pattern matching via Regex; e.g:
private class HandleMergeFields
: IFieldMergingCallback { void IFieldMergingCallback.FieldMerging(FieldMergingArgs e) { Regex
htmlPattern = new Regex("<.*?>"); if
(htmlPattern.IsMatch(e.FieldValue.ToString())) { //Create
document builder DocumentBuilder
builder = new DocumentBuilder(e.Document); //Move
cursor to field builder.MoveToField(e.Field, true); // Insert
HTML builder.InsertHtml(e.FieldValue.ToString()); // Remove
the string representation of HTML e.Text = string.Empty; } }
void IFieldMergingCallback.ImageFieldMerging(ImageFieldMergingArgs args) { // DO NOTHING }
}
I hope, this will help.
Best Regards,
Awais Hafeez Support Developer Aspose Sialkot Team Aspose - Your File Format Experts Keep in touch! We're on Twitter and Facebook
|
|
-
02-06-2012, 1:16 PM |
-
mp1
-
-
-
Joined on 01-25-2012
-
-
Posts 9
-
-
-
-
-
|
Thanks
New questions.
1. HTML fields are now working.. Yet, i have fixed them as Arial 10 in word template..but font changed to TimesRoman i guess because of Html tag in it.. Any way to fix font to Arial 10.
2. First page on my Template is working.. On second page i have table with bookmark and tables has again mail merge fields and html fields. Now based on records found in database, the records should display in table..
For example --
FOr employee id 1
Below is how it should display in word Table
Year salary
2011 100
Year salary
2010 50
and if no record found then i need to delete/or not display table at all..
Can you help how to achieve this using aspose?
Thanks a lot
MP
|
|
-
02-07-2012, 12:32 AM |
-
awais.hafeez
-
-
-
Joined on 09-16-2011
-
Lahore, Pakistan
-
Posts 2,195
-
-
-
-
-
|
Hi,
Thanks for your inquiry.
1. Please share your HTML field markup here. I will investigate the problem and provide you more information on this.
2. Instead of using Bookmarks, I would suggest you use Nested Mail Merge Regions. For more information, please visit the following link:
Please let me know if I can be of any further assistance.
Best Regards,
Awais Hafeez Support Developer Aspose Sialkot Team Aspose - Your File Format Experts Keep in touch! We're on Twitter and Facebook
|
|
-
02-10-2012, 1:07 PM |
-
mp1
-
-
-
Joined on 01-25-2012
-
-
Posts 9
-
-
-
-
-
|
I have Nested Mail merge with regions is almost working.. except for one scenario.
In my document template, i have this section where it need to show multiple data if exist.. BUT when there no record, i want to delete that page. Is there any way to programatically hide or delete page when 0 record found to populate this nested region section..?
|
|
-
02-13-2012, 4:19 AM |
-
aske012
-
-
-
Joined on 03-30-2010
-
-
Posts 3,083
-
-
-
-
-
|
Hi there,
Thanks for your inquiry.
Thanks,
Adam Skelton Programming Writer Aspose Auckland Team
|
|
-
02-13-2012, 4:19 AM |
-
awais.hafeez
-
-
-
Joined on 09-16-2011
-
Lahore, Pakistan
-
Posts 2,195
-
-
-
-
-
|
Hi,
Thanks for your inquiry. MS Word document is a flow document and does not contain any information about its layout into lines and pages. So there is no direct way to determine where page starts or ends using Aspose.Words and hence you can't delete or hide a specific page. However, if each page in your template is a separate section, then you can just remove the whole section.
Please let us know if you need more information, we are always glad to help you.
Best Regards,
Awais Hafeez Support Developer Aspose Sialkot Team Aspose - Your File Format Experts Keep in touch! We're on Twitter and Facebook
|
|
-
02-13-2012, 3:12 PM |
-
mp1
-
-
-
Joined on 01-25-2012
-
-
Posts 9
-
-
-
-
-
|
Thanks. I will work on that.. My Word template is Arial 10. I noticed that in my HTML fields there are only <p> abc....</p> tags and still it is changing font to TimesRoman 12.. How to fix font size and name?
Thanks for your all help in integrating.
|
|
-
02-13-2012, 10:29 PM |
-
awais.hafeez
-
-
-
Joined on 09-16-2011
-
Lahore, Pakistan
-
Posts 2,195
-
-
-
-
-
|
Hi,
Thanks for your inquiry.
Please note that, content inserted by Insert HTML does not inherit formatting specified in DocumentBuilder options. Whole formatting is taken from HTML snippet. If you insert HTML with no formatting specified, default formatting is used for inserted content, e.g. if font is not specified in your HTML snippet, default font will be applied (Times New Roman).
Moreover, I think, you can achieve this by using the following code:
private class HandleMergeFields : IFieldMergingCallback { void IFieldMergingCallback.FieldMerging(FieldMergingArgs e) { ... ... // Set up the node changing event handler. We will listen
for any nodes inserted during the time // that the HTML is being inserted. Change
any of these run nodes to match the font of the field // which the HTML is being
inserted at. e.Document.NodeChangingCallback = new HandleFontNodeChanging(e.Field.Start.Font); // Insert HTML builder.InsertHtml(e.FieldValue.ToString()); // Remove the font changer handler from the document. e.Document.NodeChangingCallback = null; ... ...
public class HandleFontNodeChanging : INodeChangingCallback { Aspose.Words.Font mFont;
public HandleFontNodeChanging(Aspose.Words.Font font) { mFont
= font; }
void INodeChangingCallback.NodeInserted(NodeChangingArgs args) { if (args.Node.NodeType == NodeType.Run) { Run run = (Run)args.Node;
run.Font.Name = mFont.Name; run.Font.Color = mFont.Color; run.Font.Size = mFont.Size; } }
void INodeChangingCallback.NodeInserting(NodeChangingArgs args) { // Do Nothing }
void INodeChangingCallback.NodeRemoved(NodeChangingArgs args) { // Do Nothing }
void INodeChangingCallback.NodeRemoving(NodeChangingArgs args) { // Do Nothing } }
I hope, this will help.
Best Regards,
Awais Hafeez Support Developer Aspose Sialkot Team Aspose - Your File Format Experts Keep in touch! We're on Twitter and Facebook
|
|
-
02-17-2012, 4:07 PM |
-
mp1
-
-
-
Joined on 01-25-2012
-
-
Posts 9
-
-
-
-
-
|
Thank you. Font problem is now resolved. I still have question about remove region /Section if empty.
I have two Sections and two MergeRegions in my document template. it removes one ok but it has problem removing both at same time.
here is the code snippet. Plz let me know how to solve this
' --------- Taking Care of Issues & ActionPlans----------------------------------------
doc.MailMerge.FieldMergingCallback() = New HandleMergeFields()
Dim IssueData As DataTable = New DataTable
IssueData = GetIssues(AudDocId)
IssueData.TableName = "Issues"
If IssueData.Rows.Count = 0 Then
' doc.MailMerge.CleanupOptions = MailMergeCleanupOptions.RemoveUnusedRegions
doc.Sections.RemoveAt(1)
End If
doc.MailMerge.ExecuteWithRegions(IssueData)
' ' -----------Working WIth PIOs -------------------------------------------------------
doc.MailMerge.FieldMergingCallback() = New HandleMergeFields()
Dim PIOData As DataTable = New DataTable
PIOData = GetPIOs(AudDocId)
PIOData.TableName = "PIO"
doc.MailMerge.CleanupOptions = MailMergeCleanupOptions.RemoveUnusedRegions
If PIOData.Rows.Count = 0 Then
doc.Sections.RemoveAt(2)
End If
doc.MailMerge.ExecuteWithRegions(PIOData)
|
|
-
02-20-2012, 9:16 PM |
-
awais.hafeez
-
-
-
Joined on 09-16-2011
-
Lahore, Pakistan
-
Posts 2,195
-
-
-
-
-
|
Hi,
Thanks for your inquiry. Could you please attach your input/output Word documents along with complete code here for testing? I will investigate the issue further and provide you more information.
Best Regards,
Awais Hafeez Support Developer Aspose Sialkot Team Aspose - Your File Format Experts Keep in touch! We're on Twitter and Facebook
|
|
-
02-21-2012, 1:10 PM |
-
mp1
-
-
-
Joined on 01-25-2012
-
-
Posts 9
-
-
-
-
-
|
Re: Aspose word For .NET
Attachment: Present (inaccessible)
Hi
I have attached two files here. WHen i try to remove both sections i leave with PIO section check page2. i am using code that i attached before..
Friend Overrides Function Execute(ByVal AudDocId As String) As Document
'Open the template document
' Dim doc As New Document(System.IO.Path.Combine(DocPath, "DraftAuditReport.doc"))
Dim doc As New Document(myPath & "OfficeWriter/DraftAuditReport.doc")
Dim sSQL As String
sSQL = "select right(AuditYear,2)as AuditYear,issued,Num,RptAddressee,Title,rating,FieldWkDate,RiskRating,AuditType,"
sSQL = sSQL + " PriorRptNum, PriorRptDate, PriorAuditRating,PriorAuditType,BusOverview, Scope, Keyfindings, Status, "
sSQL = sSQL + " lob, SubLob,director,ITAuditDirector,Manager,SrManager,SrITManager,ITAuditMgr,"
sSQL = sSQL + " ccList1,ccList2,ccList3,ccList4,replace(RiskCategories,';', char(13))as RiskCategories"
sSQL = sSQL + " From AuditReports where AudDocId=" & AudDocId
Dim AuditReport As DataTable = Execute1(sSQL)
'Note the table has to have its TableName set up to match the name of the mail merge region
'specified in the document in TableStart:[TableName] and TableEnd:[TableName] marks.
AuditReport.TableName = "AuditReports"
doc.MailMerge.FieldMergingCallback() = New HandleMergeFields()
Dim FieldNames() As String = {}
Dim FieldValues() As String = {}
FieldNames = New String() {"NUM", "RptAddressee", "LOB", "subLOB", _
"RiskRating", "AuditType", "issued", "Title", _
"rating", "PriorRptNUm", "PriorAuditRating", "PriorAuditType", _
"PriorRptDate", "Keyfindings", "BusOverview", "Scope", _
"RiskCategories", "director", "ITAuditDirector", "SrManager", _
"SrITManager", "Manager", "ITAuditMgr", _
"ccList1", "ccList2", "ccList3", "ccList4"}
FieldValues = New String() {AuditReport.Rows(0).Item(2).ToString(), AuditReport.Rows(0).Item(3).ToString, AuditReport.Rows(0).Item(17).ToString(), AuditReport.Rows(0).Item(18).ToString(), _
AuditReport.Rows(0).Item(7).ToString(), AuditReport.Rows(0).Item(8).ToString(), AuditReport.Rows(0).Item(1).ToString(), AuditReport.Rows(0).Item(4).ToString(), _
AuditReport.Rows(0).Item(5).ToString(), AuditReport.Rows(0).Item(9).ToString(), AuditReport.Rows(0).Item(11).ToString(), AuditReport.Rows(0).Item(12).ToString(), _
AuditReport.Rows(0).Item(10).ToString(), AuditReport.Rows(0).Item(15).ToString(), AuditReport.Rows(0).Item(13).ToString(), AuditReport.Rows(0).Item(14).ToString(), _
AuditReport.Rows(0).Item(29).ToString(), AuditReport.Rows(0).Item(19).ToString(), AuditReport.Rows(0).Item(20).ToString(), AuditReport.Rows(0).Item(22).ToString(), _
AuditReport.Rows(0).Item(23).ToString(), AuditReport.Rows(0).Item(21).ToString(), AuditReport.Rows(0).Item(24).ToString(), _
AuditReport.Rows(0).Item(25).ToString(), AuditReport.Rows(0).Item(26).ToString(), AuditReport.Rows(0).Item(27).ToString(), AuditReport.Rows(0).Item(28).ToString()}
doc.MailMerge.Execute(FieldNames, FieldValues)
' --------- Taking Care of Issues & ActionPlans----------------------------------------
doc.MailMerge.FieldMergingCallback() = New HandleMergeFields()
Dim IssueData As DataTable = New DataTable
IssueData = GetIssues(AudDocId)
IssueData.TableName = "Issues"
If IssueData.Rows.Count = 0 Then
' doc.MailMerge.CleanupOptions = MailMergeCleanupOptions.RemoveUnusedRegions
doc.Sections.RemoveAt(1)
End If
doc.MailMerge.ExecuteWithRegions(IssueData)
' ' -----------Working WIth PIOs -------------------------------------------------------
doc.MailMerge.FieldMergingCallback() = New HandleMergeFields()
Dim PIOData As DataTable = New DataTable
PIOData = GetPIOs(AudDocId)
PIOData.TableName = "PIO"
doc.MailMerge.CleanupOptions = MailMergeCleanupOptions.RemoveUnusedRegions
If PIOData.Rows.Count = 0 Then
doc.Sections.RemoveAt(2)
End If
doc.MailMerge.ExecuteWithRegions(PIOData)
Return doc
End Function
Second Question -
I want to export SQL query data into excel file.. Can i do that with Aspose?
|
|
-
02-23-2012, 1:38 AM |
-
awais.hafeez
-
-
-
Joined on 09-16-2011
-
Lahore, Pakistan
-
Posts 2,195
-
-
-
-
-
|
Re: Aspose word For .NET
Attachment: Present (inaccessible)
Hi,
Thanks for your inquiry and sorry for the delayed response.
I have found that there are five total sections in your document. The 'Issues' mail merge region lies under section 2 while the 'PIO' mail merge region is positioned under section 3 of your document. If you remove above mentioned sections in reverse order the problem would be resolved e.g:
Document doc = new
Document(@"C:\temp\DraftAuditReport.doc");
// Remove PIO section first doc.Sections.RemoveAt(2); // Then remove Issues section doc.Sections.RemoveAt(1);
Secondly, unfortunately, there is no direct way to convert Word document to Excel. However, it is possible using Aspose.Words+Aspose.Cells. I have attached a simple converter for you (See the attached class). Here is how you should use it:
Document doc = new
Document(@"C:\test\in.doc"); ConverterDoc2Xls converter = new ConverterDoc2Xls(); Workbook wb = converter.Convert(doc); wb.Save("C:\\Test\\out.xls");
I hope, this will help.
Best Regards,
Awais Hafeez Support Developer Aspose Sialkot Team Aspose - Your File Format Experts Keep in touch! We're on Twitter and Facebook
|
|
Page 1 of 2 (19 items)
1
|
|