Posted 13 January 2021, 12:43 pm EST
Hello,
How do I export C1Grid1 and Grid2 on the same excel sheet and How do I include both in a PDF with Landscape format?
Thanks,
Victor
Forums Home / ComponentOne / WinForms Edition
Posted by: Victor.m.charles.civ on 13 January 2021, 12:43 pm EST
Posted 13 January 2021, 12:43 pm EST
Hello,
How do I export C1Grid1 and Grid2 on the same excel sheet and How do I include both in a PDF with Landscape format?
Thanks,
Victor
Posted 13 January 2021, 6:15 pm EST
Hello Victor,
To export the TDB to pdf please go through the following blog post:
https://www.grapecity.com/blogs/how-to-export-multiple-c1truedbgrids-to-one-pdf-excel-file
If you want to set the orientation to landscape then use the following code:
doc.PageLayout.PageSettings.Landscape = True
doc.Export("CombinedPDF.pdf", True)
To export multiple TDB in a single excel sheet please use the same approach just by replacing the following code:
From:
doc.Export("CombinedPDF.pdf", True)
To:
doc.Export("CombinedPDF.xlsx", True)
Regards,
Prabhat Sharma.
Posted 14 January 2021, 7:52 am EST
Hello,
Thank you for your solution. I meant, If I have 3 grids on my Form, How do I export all three in a single excel worksheet.
Thanks,
Victor
Posted 14 January 2021, 7:07 pm EST
Hello Victor,
You can follow the same approach for 3 TrueDBGrids as did for the 2 TrueDBGrids in the blog sample.
The code for exporting 3 TrueDBGrids is given below:
Dim doc1 As New C1PrintDocument()
doc1.Load("1.c1d", C1DocumentFormatEnum.C1d)
Dim doc2 As New C1PrintDocument()
doc2.Load("2.c1d", C1DocumentFormatEnum.C1d)
Dim doc3 As New C1PrintDocument()
doc3.Load("3.c1d", C1DocumentFormatEnum.C1d)
' the combined document:
Dim doc As New C1PrintDocument()
' add 1st document:
While doc1.Body.Children.Count > 0
Dim ro As RenderObject = doc1.Body.Children(0)
' a render object cannot have two parents at once, so removed from original parent first:
doc1.Body.Children.RemoveAt(0)
' now add to the combined doc:
doc.Body.Children.Add(ro)
End While
' ensure a page break between the two documents:
doc.Body.Children.Add(New RenderEmpty(BreakEnum.Page))
' add 2nd document:
While doc2.Body.Children.Count > 0
Dim ro As RenderObject = doc2.Body.Children(0)
doc2.Body.Children.RemoveAt(0)
doc.Body.Children.Add(ro)
End While
doc.Body.Children.Add(New RenderEmpty(BreakEnum.Page))
While doc3.Body.Children.Count > 0
Dim ro As RenderObject = doc3.Body.Children(0)
' a render object cannot have two parents at once, so removed from original parent first:
doc3.Body.Children.RemoveAt(0)
' now add to the combined doc:
doc.Body.Children.Add(ro)
End While
' ensure a page break between the two documents:
doc.PageLayout.PageSettings.Landscape = True
doc.Export("Demo.xlsx", True)
System.Diagnostics.Process.Start("Demo.xlsx")
Regards,
Prabhat Sharma.
Posted 18 January 2021, 1:53 pm EST
Hi,
How do I modify the code below to chose the folder I want to save the file instaed of saving to the TestFiles folder?
Dim doc As New C1.C1Preview.C1PrintDocument()
doc.PageLayout.PageSettings.Landscape = True
doc.Body.Children.Add(New C1.C1Preview.RenderText(vbLf & vbLf & “AOP-6”))
doc.Body.Children.Add(New C1.C1Preview.RenderC1Printable(C1AOP5))
doc.Body.Children.Add(New C1.C1Preview.RenderText(vbLf & vbLf & “AOP-8”))
doc.Body.Children.Add(New C1.C1Preview.RenderC1Printable(C1AOP8))
doc.Body.Children.Add(New C1.C1Preview.RenderText(vbLf & vbLf & “AOP-29”))
doc.Body.Children.Add(New C1.C1Preview.RenderC1Printable(C1AOP29))
doc.Body.Children.Add(New C1.C1Preview.RenderText(vbLf & vbLf & “AOP-40”))
doc.Body.Children.Add(New C1.C1Preview.RenderC1Printable(C1AOP40))
doc.Export(“C:\TestFiles\TEST66.pdf”, True)
Thanks,
Victor
Posted 19 January 2021, 2:50 am EST
Hello Prabhat,
I noticed another issue when combining the Grids in one file or spreadsheet. How do you exclude a Grid if it’s invisible or record count is 0?
Thanks,
Victor
Posted 19 January 2021, 3:00 pm EST
Hello Prabhat,
Please disregard my last question.
Thanks,.
Victor
Posted 19 January 2021, 3:04 pm EST
Hello Prabhat,
How do I modify the code below to include each AOP in a separate worksheet? For example I would to create an excel file with 4 separate worksheets.
If ComboBox4.SelectedIndex = 1 Then
Dim doc1 As New C1.C1Preview.C1PrintDocument()
doc1.Body.Children.Add(New C1.C1Preview.RenderText(vbLf & vbLf & “AOP-6”))
doc1.Body.Children.Add(New C1.C1Preview.RenderC1Printable(C1AOP5))
doc1.Body.Children.Add(New C1.C1Preview.RenderText(vbLf & vbLf & “AOP-8”))
doc1.Body.Children.Add(New C1.C1Preview.RenderC1Printable(C1AOP8))
doc1.Body.Children.Add(New C1.C1Preview.RenderText(vbLf & vbLf & “AOP-20”))
doc1.Body.Children.Add(New C1.C1Preview.RenderC1Printable(C1AOP29))
doc1.Body.Children.Add(New C1.C1Preview.RenderText(vbLf & vbLf & “AOP-40”))
doc1.Body.Children.Add(New C1.C1Preview.RenderC1Printable(C1AOP40))
doc1.Export(“AMIS_Excel_Fle.xlsx”, True)
System.Diagnostics.Process.Start(“AMIS_Excel_Fle.xlsx”)
End If
Thanks,
Victor
Posted 19 January 2021, 5:23 pm EST
Hello Victor,
>>How do I modify the code below to choose the folder I want to save the file instead of saving to the TestFiles folder?
You can use the code snippet given below:
string dir = @"C:\YourFolderName";
// If directory does not exist, create it
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
doc.Export("C:\YourFolderName\TEST66.pdf", True)
>>I would to create an excel file with 4 separate worksheets.
You can go through the following blog post to learn how to export multiple C1TrueDbGrids to excel sheets:
https://www.grapecity.com/blogs/how-to-export-multiple-c1truedbgrids-to-excel-sheets
Regards,
Prabhat Sharma.
Posted 21 January 2021, 3:31 am EST
Posted 21 January 2021, 4:40 pm EST
Hi Victor,
You can download the same from here: https://www.dropbox.com/s/tluady2bjl5y3pa/ExportMultipleTDB_OneExcel_MultipleSheets_VB.zip?dl=0
The sample works fine at our end.
Thanks.