Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 503
  • Last Modified:

Create a PowerPoint table from TAB delimited string

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
TommyTwoPints
Asked:
TommyTwoPints
  • 4
  • 3
  • 2
1 Solution
 
Bob LearnedCommented:
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
 
GlennaShawCommented:
You should be able to modify one of these:
http://www.pptfaq.com/index.html#name_Working_with_external_data
0
 
TommyTwoPintsAuthor Commented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Bob LearnedCommented:
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
 
TommyTwoPintsAuthor Commented:
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
 
Bob LearnedCommented:
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
 
GlennaShawCommented:
Couldn't you modify this one?
http://www.pptfaq.com/FAQ00891.htm
0
 
TommyTwoPintsAuthor Commented:
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
 
TommyTwoPintsAuthor Commented:
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

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now