Spire.Presentation is a professional PowerPoint® compatible library that enables developers to create, read, write, modify, convert and Print PowerPoint documents. Get free and professional technical support for Spire.Presentation for .NET, Java, Android, C++, Python.
Thu Feb 18, 2021 4:39 am
I have a excel data as image:
1.PNG
I embed to pptx file :
- Code: Select all
Dim book As New Spire.Xls.Workbook()
book.LoadFromFile("D:\1.DTP_Autom\PowerPoit_Demo\t2.xlsx")
Dim image As Image = book.Worksheets(0).ToImage(1, 1, 3, 3)
Dim ppt As New Presentation()
Dim oleImage As IImageData = ppt.Images.Append(image)
Dim rec As New Rectangle(60, 60, image.Width, image.Height)
Using ms As New MemoryStream()
book.SaveToStream(ms)
ms.Position = 0
Dim oleObject As Spire.Presentation.IOleObject = ppt.Slides(0).Shapes.AppendOleObject("excel", ms.ToArray(), rec)
oleObject.SubstituteImagePictureFillFormat.Picture.EmbedImage = oleImage
oleObject.ProgId = "Excel.Sheet.12"
End Using
ppt.SaveToFile("D:\1.DTP_Autom\PowerPoit_Demo\InsertOle.pptx", Spire.Presentation.FileFormat.Pptx2007)
Result:
2.PNG
How can fix size of Rectangle to Excel Data?
Login to view the files attached to this post.
-
daitranthanhhoa
-
- Posts: 51
- Joined: Mon Sep 19, 2016 3:04 am
Thu Feb 18, 2021 9:09 am
Hello,
Since the Excel file has margins by default, there will be blank areas around the data when using the "ToImage" method to convert Excel data to images. Please refer to the following code to set the margins to 0 before converting it to image.
- Code: Select all
'...
Dim book As New Spire.Xls.Workbook()
book.LoadFromFile("test.xlsx")
Dim pageSetup = book.Worksheets(0).PageSetup
pageSetup.LeftMargin = 0
pageSetup.RightMargin = 0
pageSetup.TopMargin = 0
pageSetup.BottomMargin = 0
Dim image As Image = book.Worksheets(0).ToImage(1, 1, 3, 3)
'...
If there are any other issues, please feel free to contact us.
Sincerely,
Brian
E-iceblue support team
-
Brian.Li
-
- Posts: 1271
- Joined: Mon Oct 19, 2020 3:04 am
Thu Feb 18, 2021 9:34 am
Thank you your helps.
Size of Rectangle fixed to Excel Data after Create, But After click to edit , size of Rectangle occur this problem. Refer image.
3.png
Can fix this problem?
Login to view the files attached to this post.
-
daitranthanhhoa
-
- Posts: 51
- Joined: Mon Sep 19, 2016 3:04 am
Thu Feb 18, 2021 10:58 am
Hello,
Thanks for your feedback.
Please add this line to set the ole size. If there are any other issues, please feel free to contact us.
- Code: Select all
book.SetOleSize(1, 1, 3, 3)
Sincerely,
Brian
E-iceblue support team
-
Brian.Li
-
- Posts: 1271
- Joined: Mon Oct 19, 2020 3:04 am
Fri Feb 19, 2021 1:21 am
Can setting Scale of Size to 100%?
4.png
Login to view the files attached to this post.
-
daitranthanhhoa
-
- Posts: 51
- Joined: Mon Sep 19, 2016 3:04 am
Fri Feb 19, 2021 9:08 am
Hello,
Please refer to the following code to achieve your requirement. If there are any other issues, please feel free to contact us.
- Code: Select all
Dim book As New Spire.Xls.Workbook()
book.LoadFromFile("test.xlsx")
Dim pageSetup = book.Worksheets(0).PageSetup
book.SetOleSize(1, 1, 3, 3)
pageSetup.LeftMargin = 0
pageSetup.RightMargin = 0
pageSetup.TopMargin = 0
pageSetup.BottomMargin = 0
Dim image As Image = book.Worksheets(0).ToImage(1, 1, 3, 3)
Dim unitCvtr = New Spire.Pdf.Graphics.PdfUnitConvertor()
Dim pointWidth = unitCvtr.ConvertUnits(image.Width, Spire.Pdf.Graphics.PdfGraphicsUnit.Pixel, Spire.Pdf.Graphics.PdfGraphicsUnit.Point)
Dim pointHeight = unitCvtr.ConvertUnits(image.Height, Spire.Pdf.Graphics.PdfGraphicsUnit.Pixel, Spire.Pdf.Graphics.PdfGraphicsUnit.Point)
Dim ppt As New Presentation()
Dim oleImage As IImageData = ppt.Images.Append(image)
Dim rec As New RectangleF(60, 60, pointWidth, pointHeight)
Using ms As New MemoryStream()
book.SaveToStream(ms)
ms.Position = 0
Dim oleObject As Spire.Presentation.IOleObject = ppt.Slides(0).Shapes.AppendOleObject("excel", ms.ToArray(), rec)
oleObject.SubstituteImagePictureFillFormat.Picture.EmbedImage = oleImage
oleObject.ProgId = "Excel.Sheet.12"
End Using
ppt.SaveToFile("InsertOle.pptx", Spire.Presentation.FileFormat.Pptx2007)
Sincerely,
Brian
E-iceblue support team
-
Brian.Li
-
- Posts: 1271
- Joined: Mon Oct 19, 2020 3:04 am
Fri Feb 26, 2021 6:16 am
Hello,
Greetings from E-iceblue!
How is your issue now? Did the code we provided work for you? Any feedback will be greatly appreciated.
Sincerely,
Brian
E-iceblue support team
-
Brian.Li
-
- Posts: 1271
- Joined: Mon Oct 19, 2020 3:04 am
Mon Mar 01, 2021 4:36 am
Thank you. It is ok.
-
daitranthanhhoa
-
- Posts: 51
- Joined: Mon Sep 19, 2016 3:04 am
Tue Mar 02, 2021 1:38 am
You are welcome.
If you encounter any issues related to our products in the future, please feel free to contact us.
Sincerely,
Brian
E-iceblue support team
-
Brian.Li
-
- Posts: 1271
- Joined: Mon Oct 19, 2020 3:04 am