Changeset 10628


Ignore:
Timestamp:
2005-09-23T11:26:43+12:00 (19 years ago)
Author:
chi
Message:

Modify VB script to use late binding technique to solve the problem of running the script for
Multiple Office versions.

Location:
trunk/winbin/bin
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/winbin/bin/pptextract.frm

    r10571 r10628  
    3535Attribute VB_Exposed = False
    3636Private Sub Form_Load()
    37     Dim pa As PowerPoint.Application
    38     Set pa = CreateObject("PowerPoint.Application")
    39     pa.Visible = True
    40    
    41     Dim ppts As PowerPoint.Presentations
    42     Set ppts = pa.Presentations
     37    'For solving the backward compatability of MS Automation with VB script
     38    'We need to use the late binding technique, in which mean that we need to
     39    'define all Office Automation variable as an Object first and it can then
     40    'to decide the office version at run-tim.
     41    Dim objPA As Object
     42    Set objPA = CreateObject("PowerPoint.Application")
     43    objPA.Visible = True
     44   
     45    Dim objPPTs As Object
     46    Set objPPTs = objPA.Presentations
    4347           
    4448    htm = False
     
    4953    meta = False
    5054   
    51     'cmdln = "-g " & Chr(34) & "C:\chi\gsdl\collect\PPTTest2\import\16-A.ppt" & Chr(34) & Chr(34) & "C:\chi\gsdl\collect\PPTTest2\tmp\16-A" & Chr(34)
     55    'cmdln = "-g " & Chr(34) & "H:\chi\gsdl\collect\PPTTest\import\LITA-2004.ppt" & Chr(34) & Chr(34) & "H:\chi\gsdl\collect\PPTTest\tmp\LITA-2004" & Chr(34)
    5256    cmdln = LCase(Command())
    5357    'MsgBox ("Command:" + cmdln)
     
    5559    outputdir = getoutput(cmdln)
    5660    File = Left(cmdln, InStr(cmdln, ".ppt") + 3)
    57     'MsgBox ("File:" + File)
    5861    item_file = Left(cmdln, InStr(cmdln, ".ppt"))
    5962    args = getargs(File)
    60     'MsgBox ("agr:" + args)
    6163    direc = getdir(File)
    62     'MsgBox ("direc:" + direc)
    6364    File = getfile(File)
    64     'MsgBox ("File:" + File)
    65    
     65       
    6666    item_file = getfile(item_file)
    67        
    68     If InStr(args, "h") Then htm = True
     67    'We don't use this script to convert the PPT to html, instead, we use
     68    'the open source come with Greenstone package
    6969    If InStr(args, "j") Then jpg = True
    7070    If InStr(args, "g") Then gif = True
    7171    If InStr(args, "p") Then png = True
    72     If InStr(args, "o") Then old = True
    73     If InStr(args, "m") Then meta = True
    74 
    75     Dim item, text
    76     'As Object
    77     Dim fso
     72   
     73    Dim item, text As Object
     74    Dim fso As Object
    7875    Set fso = CreateObject("Scripting.FileSystemObject")
    7976   
    80     ' Modified for apply to GSII environment setting
    81     'MsgBox ("OUTPUT_dir:" + outputdir)
     77    'Modified for apply to GSII environment setting
    8278    output_tmp = Left(outputdir, InStr(outputdir, "\tmp") + 3)
    8379    'output_tmp = Mid(outputdir, 2, InStr(outputdir, "\tmp") + 3)
     
    109105    Source = direc + File
    110106    'MsgBox ("Src:" + Source)
    111     ppts.Open (Source)
     107    objPPTs.Open (Source)
    112108                           
    113109    'do stuff
     
    115111    Dim slide_shape As Shape
    116112    j = 2
    117     For slide_count = 1 To ppts(1).Slides.Count
    118         current_slide = ppts(1).Slides(slide_count).Name
     113    For slide_count = 1 To objPPTs(1).Slides.Count
     114        current_slide = objPPTs(1).Slides(slide_count).Name
    119115        'generate a text version
    120116        Set text = fso.CreateTextFile(outputdir + "\Slide" + CStr(slide_count) + ".txt", ForWriting, True)
    121         'Set text = CreateObject("ADODB.Stream")
    122         'text.Open
    123         'text.Position = 0
    124         'text.Charset = "UTF-8"
    125         If (ppts(1).Slides(slide_count).Shapes.HasTitle) Then
    126             slide_title = ppts(1).Slides(slide_count).Shapes.Title.TextFrame.TextRange
     117        If (objPPTs(1).Slides(slide_count).Shapes.HasTitle) Then
     118            slide_title = objPPTs(1).Slides(slide_count).Shapes.Title.TextFrame.TextRange
    127119        Else
    128             slide_title = ppts(1).Slides(slide_count).Name
     120            slide_title = objPPTs(1).Slides(slide_count).Name
    129121        End If
    130122        slide_text = ""
    131123        found_text = True
    132         For iShape = 1 To ppts(1).Slides(slide_count).Shapes.Count
    133             If (ppts(1).Slides(slide_count).Shapes(iShape).TextFrame.HasText) Then
    134                 slide_text = ppts(1).Slides(slide_count).Shapes(iShape).TextFrame.TextRange.text
     124        For iShape = 1 To objPPTs(1).Slides(slide_count).Shapes.Count
     125            If (objPPTs(1).Slides(slide_count).Shapes(iShape).TextFrame.HasText) Then
     126                slide_text = objPPTs(1).Slides(slide_count).Shapes(iShape).TextFrame.TextRange.text
    135127                'MsgBox ("Slide_text:" + slide_text)
    136128                If slide_text <> "" Then
     
    139131                Else
    140132                    text.WriteLine ("This slide has no text")
    141                     'text.WriteText ("This slide has no text")
    142133                End If
    143134            End If
     
    147138        'text.Close
    148139        'j = j + 1
    149         If ppts(1).Slides.Count >= 1 And slide_count < ppts(1).Slides.Count Then
    150             next_slide = ppts(1).Slides(slide_count + 1).Name
     140        If objPPTs(1).Slides.Count >= 1 And slide_count < objPPTs(1).Slides.Count Then
     141            next_slide = objPPTs(1).Slides(slide_count + 1).Name
    151142        Else
    152143            nextf = " "
    153144        End If
    154145        If htm Then
    155             ' Not developed for convert to html yet
     146            'Not developed for converting to html yet
    156147            'Currently, if the user choose to convert the PPT to the html file
    157             'We will only allow users to use the open source method
     148            'We will only allow users to use the open source method through Greenstone
    158149        End If
    159150        If gif Then
     
    201192        'ppts(1).SaveAs outputdir, ppSaveAsHTMLv3
    202193    ElseIf gif Then
    203         ppts(1).SaveAs outputdir, ppSaveAsGIF
     194        objPPTs(1).SaveAs outputdir, ppSaveAsGIF
    204195    ElseIf jpg Then
    205         ppts(1).SaveAs outputdir, ppSaveAsJPG
     196        objPPTs(1).SaveAs outputdir, ppSaveAsJPG
    206197    ElseIf png Then
    207         ppts(1).SaveAs outputdir, ppSaveAsPNG
     198        objPPTs(1).SaveAs outputdir, ppSaveAsPNG
    208199    End If
    209200               
     
    213204    'item.SaveToFile outputdir + "\" + item_file + "item"
    214205    item.Close
    215     ppts(1).Close
     206    objPPTs(1).Close
    216207    Set fso = Nothing
    217208    Set text = Nothing
    218209    Set item = Nothing
    219     pa.Quit
     210    objPA.Quit
    220211End
    221212End Sub
    222213Function getoutput(line)
    223     'MsgBox ("CMDLN:" + line)
    224214    cmdln = line
    225215    While InStr(cmdln, ".ppt")
    226         'cmdln = LTrim(RTrim(Right(cmdln, Len(cmdln) - (InStr(cmdln, ".ppt") + 4))))
    227216        cmdln = Trim(Right(cmdln, Len(cmdln) - (InStr(cmdln, ".ppt") + 4)))
    228217        cmdln = Trim(Mid(cmdln, 2, Len(cmdln) - 2))
    229218    Wend
    230219    getoutput = cmdln
    231     'MsgBox ("OUTPUTDIR:" + getoutput)
    232 End Function
     220    End Function
    233221Function getargs(line)
    234222    x = LTrim(line)
     
    249237    Wend
    250238    getdir = direc
    251     'MsgBox ("GetDIr:" + getdir)
    252239End Function
    253240Function getfile(line)
     
    257244    Wend
    258245    getfile = x
    259     End Function
     246End Function
    260247Sub itemxml(out_item, thisfile, txtfile, num, slide_title)
    261248    out_item.WriteLine ("   <Page pagenum=" + Chr(34) + CStr(num) + Chr(34) + " imgfile=" + Chr(34) + thisfile + Chr(34) + " txtfile=" + Chr(34) + txtfile + Chr(34) + ">")
  • trunk/winbin/bin/pptextract.vbp

    r10571 r10628  
    11Type=Exe
    2 Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\WINDOWS\system32\STDOLE2.TLB#OLE Automation
     2Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\WINDOWS\system32\stdole2.tlb#OLE Automation
    33Reference=*\G{91493440-5A91-11CF-8700-00AA0060263B}#2.6#0#C:\Program Files\Microsoft Office\OFFICE11\MSPPT.OLB#Microsoft PowerPoint 9.0 Object Library
    44Form=pptextract.frm
    5 IconForm="Form1"
    65Startup="Form1"
    76ExeName32="pptextract.exe"
Note: See TracChangeset for help on using the changeset viewer.