ASP.NET Access Word class, there is a lot of features you need, lookup, tables! VB

xiaoxiao2021-03-06  59

Public class vbwordapp private owordapplic as word.Applicationclass private public sub vbwordapp () Activation CoM Word interface OWordApplic = new word.ApplicationClass

End Sub

'Open a file (the file must exists) And Activate It public sub open (Byval Strfilename As String) Dim FileName As String Dim OnlyRead As Boolean Dim Isvisible As Boolean Dim Missing

Filename = strfilename online = false isvisible = true missing = system.reflection.Missing.Value

Odoc = OwordApplic.documents.Open (Filename, Missing, Onlyread, Missing, Missing, Missing, missing, missing, missing, missing odoc.activate ()

End Sub

'Open a document publish () Dim missing missing = system.reflection.Missing.Value Odoc = OwordApplic.documents.add (missing, missing, missing, miss) odoc.activate ()

End Sub

Public Sub Quit () DIM MISSING MISSING = system.reflection.Missing.Value OwordApplic.Application.quit (Missing, missing, missing)

End Sub

Public Sub Save () odoc.save () End Sub

Public Sub Saveas (Byval StrfileName As String) Dim missing Dim FileName As String

Missing = system.reflection.Missing.Value filename = strfilename

Odoc.saveas (Filename, Missing, Missing, Missing, Missing, Missing, missing, missing, missing, missing, missing, missing

End Sub

Public Sub Saveashtml (Byval Strfilename As String) DIM MISSING MISSING = System.Reflection.Missing.Value

DIM filename as string filename = strfilename

Dim format format = CInt (Word.WdSaveFormat.wdFormatHTML) oDoc.SaveAs (filename, format, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing) End Sub

Public Sub INSERTTEXT (BYVAL STRText) OWordApplic.Serection.Typetext (StRText)

End Sub

Public Sub INSERTLINEBREAK () OWORDAPPLIC.SELECTION.TYPEPARAGRAPH ()

End Sub

Public Sub INSERTLINEBREAK (BYVAL NLINE AS INTEGER) DIM I for i = 1 to nLINE OWORDAPPLIC.SELECTION.TYPEPARAGRAPH () NEXT

End Sub

Public Sub SetAlignment (Byval Strtype As String)

SELECT CASE STRTYPE

Case "center" oWordApplic.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter Case "left" oWordApplic.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft Case "right" oWordApplic.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment. WDALIGNPARAGRAPHRIGHT CASE "Justify" OWordApplic.selection.ParagraphFormat.Alignment = Word.wdparagraphagramhalignment.wdalignParagraphjustify

End Select End Sub

Public Sub setfont (ByVal strtype As String) Select Case strtype Case "bold" oWordApplic.Selection.Font.Bold = 1 Case "italic" oWordApplic.Selection.Font.Italic = 1 Case "underlined" oWordApplic.Selection.Font.Subscript = 0

End Select End Sub

'Disable All the Style Public SUB SetFont ()

OWordApplic.Selection.Font.Bold = 0 Owordapplic.selection.font.italic = 0 OWordApplic.selection.font.subscript = 0nd Sub

Public SUB setFontName (Byval Strtype As String)

OWordApplic.selection.font.name = start.font.name = startpepe

End Sub

Public SUB setFontSize (Byval nsize as integer)

OWordApplic.selection.font.size = nsize end sub

Public Sub INSERTPAGEBREAK () DIM PBREAK AS INTEGER PBREAK = CINT (Word.WDBreakType.wdpageBreak) OWordApplic.Serection.InsertBreak (PBREAK) End Sub

'Go to a predefined bookmark, if The Bookmark Doesn't Exists the application will raise an error

Public Sub gotobookmark (Byval strbookmarkname as string)

Dim missing missing = System.Reflection.Missing.Value Dim Bookmark Bookmark = CInt (Word.WdGoToItem.wdGoToBookmark) Dim namebookmark NameBookMark = strBookMarkName oWordApplic.Selection.GoTo (Bookmark, missing, missing, namebookmark) End Sub

Public Sub Gotothend () DIM MISSING, UNIT MISSING = System.Reflection.Missing.Value unit = word.wdunits.wdstory OwordApplic.Selection.endKey (Unit, missing) end sub

Public Sub Gotothebeginning () DIM MISSING, UNIT MISSING = System.Reflection.Missing.Value unit = word.wdunits.wdstory OwordApplic.Selection.homekey (Unit, missing) End Sub

Public Sub GotoThetable (Byval NTable As Integer)

Dim missing, what, which, count missing = system.reflection.Missing.Value

What = word.wdunits.wdtable

Which = word.wdgotoducture.wdgotofirst

Count = 1

OWordApplic.selection.goto (what, which, count, missing) OWordApplic.selection.find.clearformatting ()

OWordApplic.Serection.Text = "" End Sub

Public Sub Gotorightcell () DIM MISSING, DIRECTION MISSING = System.Reflection.Missing.Value

Direction = Word.wdunits.wdcell OwordApplic.Selection.Moveright (Direction, missing, missing) End Sub

Public Sub gotoleftcell ()

DIM MISSING, DIRECTION MISSING = System.Reflection.Missing.Value

Direction = word.wdunits.wdcell owordapplic.selection.moveleft (direction, missing, missing) End Sub

Public Sub Gotodowncell () DIM MISSING, DIRECTION MISSING = System.Reflection.Missing.Value

Direction = word.wdunits.wdline owordapplic.selection.movedown (direction, missing, missing) End Sub

Public Sub Gotoupcell () DIM MISSING, DIRECTION MISSING = System.Reflection.Missing.Value

Direction = word.wdunits.wdline owordapplic.selection.moveup (direction, missing, missing) End Sub

'this function doesn't Work Public Sub Insertpagenumber (Byval Bheader As Boolean) Dim missing, alignment, bfirstpage, bf missing = system.reflection.Missing.Value

BfirstPage = false bf = true select case strtype

Case "Center" alignment = Word.WdPageNumberAlignment.wdAlignPageNumberCenter oWordApplic.Selection.HeaderFooter.PageNumbers.Item (1) .Alignment = Word.WdPageNumberAlignment.wdAlignPageNumberCenter

Case "Right" alignment = Word.WdPageNumberAlignment.wdAlignPageNumberRight oWordApplic.Selection.HeaderFooter.PageNumbers.Item (1) .Alignment = Word.WdPageNumberAlignment.wdAlignPageNumberRight

Case "Left" alignment = word.wdpagenumberalignment.wdalignpagenumberleft OwordApplic.selection.headerfooter.pagenumbers.add (alignment, bfirstpage) End SELECT End Sub

END CLASS

转载请注明原文地址:https://www.9cbs.com/read-119587.html

New Post(0)