Solved

Create a PowerPoint table from TAB delimited string

Posted on 2008-10-27
9
486 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 3

Author Comment

by:TommyTwoPints
Comment Utility
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
Comment Utility
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
Comment Utility
Couldn't you modify this one?
http://www.pptfaq.com/FAQ00891.htm
0
 
LVL 3

Author Comment

by:TommyTwoPints
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Most folk recognise that Microsoft Excel, being a numbers-and-formulae-centric application attracts programmers due to the natural fit in mindset. Conversly, when opening Microsoft's dominant presentation creative application, few consider what…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This video teaches viewers how to add transitions to their Slideshows and how to set up timing for the transitions.
This video teaches viewers how to create handouts from their slides and helps them decide how many slides to include per handout.

772 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

11 Experts available now in Live!

Get 1:1 Help Now