Solved

Create a PowerPoint table from TAB delimited string

Posted on 2008-10-27
9
490 Views
Last Modified: 2013-11-07
Hi Experts,

Is there a way I can create a table (shape) in PowerPoint from a TAB delimited string. I am using VB.NET to automate PowerPoint with the XP PIA's.

I would like this to work with office XP and above,

Thanks in advance

Tom
0
Comment
Question by:TommyTwoPints
  • 4
  • 3
  • 2
9 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 22814902
Here is something that I created from a bigger code set, that goes against Office 2000, so it may or may not be a good starting place.


Imports System.Runtime.InteropServices
 

Public Class PowerPointServices
 

    Public Shared Sub CreatePresentationWithTable(ByVal presentationPath As String, ByVal tableText As String(,))

        Dim app As New PowerPoint.Application()

        app.Visible = Office.MsoTriState.msoTrue
 

        Dim presentation As PowerPoint.Presentation = app.Presentations.Open(presentationPath)
 

        Dim slide As PowerPoint.Slide = presentation.Slides.Item(1)

        slide.Select()
 

        Dim rowCount As Integer = tableText.GetUpperBound(0)

        Dim columnCount As Integer = tableText.GetUpperBound(1)
 

        slide.Shapes.AddTable(rowCount + 1, columnCount + 1)
 

        For row As Integer = 0 To rowCount

            For column As Integer = 0 To columnCount

                slide.Shapes.Item(1).Table.Rows.Item(0).Cells.Item(0).Shape.TextFrame.TextRange.Text = tableText(row, column)

            Next column

        Next row
 
 

        presentation.SaveAs(presentationPath)

        presentation.Close()

        app.Quit()
 

        Marshal.ReleaseComObject(slide)

        Marshal.ReleaseComObject(presentation)

        Marshal.ReleaseComObject(app)
 

    End Sub
 

End Class

Open in new window

0
 
LVL 21

Expert Comment

by:GlennaShaw
ID: 22816127
You should be able to modify one of these:
http://www.pptfaq.com/index.html#name_Working_with_external_data
0
 
LVL 3

Author Comment

by:TommyTwoPints
ID: 22828562
Thankyou both for your solutions. I take it there is no way of pasting a set of data to a PowerPoint table then?
With MSGraph.Charts, you can paste a TAB delimited string to the datagrid and it populates the charts very quickly. Doing things cell by cell is very slow with large amounts of data which is a bit of a problem.
Rgds
Tom
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 22829590
Tom,

Let's not say that it is impossible, I just haven't needed to find a way (until now).  How is it done with MSGraph.Charts?
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 3

Author Comment

by:TommyTwoPints
ID: 22829778
You build a TAB delimited string based on your data
Copy the TAB delimited string to the clipboard
Create the range in the Chart.DataSheet <--- This should be the exact range your data will fill. If a different size range is selected then a message box appears asking you to confirm.
Call the Range.Paste method that will paste the data from the clipboard to the DataGrid.
If you need a code sample, let me know,
Rgds
Tom
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 22829795
Tom,

There might be the same thing with the PowerPoint Range object.  You would need to get a reference to a Range object (which I think is doable) for the table.
0
 
LVL 21

Expert Comment

by:GlennaShaw
ID: 22843243
Couldn't you modify this one?
http://www.pptfaq.com/FAQ00891.htm
0
 
LVL 3

Author Comment

by:TommyTwoPints
ID: 22860709
Thankyou both for your help so far.
TheLearnedOne: As far as I can see, there is no Range object in PowerPoint. There is however a CellRange Interface which looks the most promising but I am not clear on hwow to use the interface without the table already existing.
GlennaShaw: I have seen that before but I am not sure it works with Office XP and above. I think that is only avaliable in Office 2003/2007.
0
 
LVL 3

Author Comment

by:TommyTwoPints
ID: 22865425
After some research of my own, I have decided to go with TheLearnedOne's solution. It seems to be the only way I can populate a table correctly over Office XP, 2003 and 2007.
Thanks alot
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Please explain "Multi-Tenant Services" 5 65
How can I use SQL Stored Procedure to return FedEx Zone 17 41
Can't edit data in PowerPoint 2013 6 16
Help with LINQ and XML 10 27
Background   Certain code in VBA requires initialization, such as application events. The app initialization is often triggered by the Auto_Open sub which is a special procedure that runs when an add-in loads. More significantly, this sub does n…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video teaches viewers how to create handouts from their slides and helps them decide how many slides to include per handout.
The viewer will learn how to edit the master slide. They will also learn how to combine multiple themes into one master slide to use them in their presentation.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now