如何使用VB.NET提高演示引擎的性能? [英] how to improve presentation Engine Performance using VB.NET ?
本文介绍了如何使用VB.NET提高演示引擎的性能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
我已经使用VB.NET应用程序作为演示引擎.当我使用PPT 2007时,请通过我的Presentation Engine下载.它会花费更多时间.如果我收到了CopySlideFormatting()函数的评论,则下载时间会减少.谁能告诉我我必须修改的地方.以下是我的功能:-
Hello,
I have using VB.NET Application as a Presentation Engine. While i am using PPT 2007 download with my Presentation Engine. it gets more time.and if i am commented CopySlideFormatting() functionthen it takes less time for downloading. can anyone tell me where i have to modify. following are my function:-
Private Sub CopySlideFormatting(ByVal sldSource As Slide, ByVal sldDest As Slide)
log.Debug("Entering CopySlideFormatting()")
Dim count As Integer = sldSource.Shapes.Count
Dim sh1, sh2 As PowerPoint.Shape
For index As Integer = 1 To count
sh1 = sldSource.Shapes(index)
sh2 = sldDest.Shapes(index)
CopyShapeFormatting(sh1, sh2)
Next
log.Debug("Exiting CopySlideFormatting()")
End Sub
Private Sub CopyShapeFormatting(ByVal sh1 As PowerPoint.Shape, ByVal sh2 As PowerPoint.Shape)
log.Debug("Entering CopyShapeFormatting()")
Dim tr1, tr2 As Microsoft.Office.Core.TextRange2
Dim str1, str2 As Microsoft.Office.Core.TextRange2
Dim para1, para2 As Microsoft.Office.Core.TextRange2
Dim run1, run2 As Microsoft.Office.Core.TextRange2
If sh1.HasTextFrame Then
If sh1.TextFrame2.HasText Then
tr1 = sh1.TextFrame2.TextRange
tr2 = sh2.TextFrame2.TextRange
Dim index2 As Integer = 1
Dim srcParaIndex As Integer = 1
Dim srcRunIndex As Integer = 1
Dim destRunIndex As Integer = 1
Dim runCharCount As Integer
Dim totalCharCount As Integer = 0
'' Copy paragraph format
index2 = 1
For Each str1 In tr1
str2 = tr2.Item(index2)
For srcParaIndex = 1 To str1.Paragraphs.Count
Try
para1 = str1.Paragraphs(srcParaIndex, 1)
Catch ex As Exception
Exit For
End Try
Try
para2 = str2.Paragraphs(srcParaIndex, 1)
CopyParagraphFormat(para1.ParagraphFormat, para2.ParagraphFormat)
totalCharCount = 0
'' Copy font for each run
For srcRunIndex = 1 To para1.Runs.Count
Try
run1 = para1.Runs(srcRunIndex, 1)
Catch ex As Exception
'' When we encounter first exception it means we may run out of index (total number of runs)
Exit For
End Try
Try
runCharCount = run1.Length
run2 = para2.Characters(totalCharCount + 1, runCharCount)
totalCharCount = totalCharCount + runCharCount
''run2 = para2.Runs(destRunIndex, 1)
CopyFont(run1.Font, run2.Font)
Catch ex As Exception
log.Warn("Exception in CopyShapeFormatting", ex)
End Try
Next
Catch ex As Exception
log.Warn("Exception in CopyShapeFormatting", ex)
End Try
Next
index2 = index2 + 1
Next
End If
End If
If sh1.Type = MsoShapeType.msoGroup Then
Try
Dim count As Integer = sh1.GroupItems.Count
For index As Integer = 1 To count
CopyShapeFormatting(sh1.GroupItems(index), sh2.GroupItems(index))
Next
Catch ex As Exception
log.Warn("Exception in CopyShapeFormatting", ex)
End Try
End If
log.Debug("Exiting CopyShapeFormatting()")
End Sub
Private Sub CopyFont(ByVal fontSource As Microsoft.Office.Core.Font2, ByVal fontDest As Microsoft.Office.Core.Font2)
With fontDest
.Allcaps = fontSource.Allcaps
.AutorotateNumbers = fontSource.AutorotateNumbers
.Bold = fontSource.Bold
.Caps = fontSource.Caps
.DoubleStrikeThrough = fontSource.DoubleStrikeThrough
.Equalize = fontSource.Equalize
.Italic = fontSource.Italic
.Size = fontSource.Size
.Smallcaps = fontSource.Smallcaps
.SoftEdgeFormat = fontSource.SoftEdgeFormat
.Strike = fontSource.Strike
.StrikeThrough = fontSource.StrikeThrough
.Subscript = fontSource.Subscript
.Superscript = fontSource.Superscript
.UnderlineStyle = fontSource.UnderlineStyle
End With
End Sub
Private Sub CopyParagraphFormat(ByVal pfSource As Microsoft.Office.Core.ParagraphFormat2, ByVal pfDest As Microsoft.Office.Core.ParagraphFormat2)
With pfDest
.Alignment = pfSource.Alignment
.BaselineAlignment = pfSource.BaselineAlignment
.FarEastLineBreakLevel = pfSource.FarEastLineBreakLevel
.FirstLineIndent = pfSource.FirstLineIndent
.HangingPunctuation = pfSource.HangingPunctuation
.IndentLevel = pfSource.IndentLevel
.LeftIndent = pfSource.LeftIndent
.LineRuleAfter = pfSource.LineRuleAfter
.LineRuleBefore = pfSource.LineRuleBefore
.LineRuleWithin = pfSource.LineRuleWithin
.RightIndent = pfSource.RightIndent
.SpaceAfter = pfSource.SpaceAfter
.SpaceBefore = pfSource.SpaceBefore
.SpaceWithin = pfSource.SpaceWithin
.TextDirection = pfSource.TextDirection
.WordWrap = pfSource.WordWrap
End With
End Sub
添加了代码块-OriginalGriff [/edit]
[edit]Code block added - OriginalGriff[/edit]
推荐答案
这是由于您对Powerpoint对象进行了大量的调用.由于Power Point进程是所谓的进程外进程,因此需要对呼叫和数据进行整理,这不是一个很轻松的操作.例如,一次复制整个幻灯片会更有效率(最好是一次通话或尽可能少的通话).您需要减少对Power Point对象模型的调用次数,以加快自动化过程.
这里是一个与其他良好链接有关的链接:
http://www.xtremevbtalk.com/showthread.php?t=160459 [ ^ ]
祝你好运!
This is due to the large number of calls you make to the power point objects. Because the power point process is so-called out-of-process the calls and data need to be marshalled and that isn''t a very light operation. It would for example be much more efficient to copy the complete slide at once (preferable in a single or as little calls possible). You need to reduce the number of calls to the power point object model to speed up the automation process.
Here a link with som other good links about it:
http://www.xtremevbtalk.com/showthread.php?t=160459[^]
Good luck!
这篇关于如何使用VB.NET提高演示引擎的性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文