Develop ASP components in VB to develop ASP components to select BLOG from Adonis2222

xiaoxiao2021-03-06  40

In the actual development of the MIS system, we sometimes need the data on the current page in the format of the Word document to the local, which is not difficult. But sometimes we need to make some settings on the format of the downloaded Word document, such as title color, font size, word spacing, etc., then we have to use the macro function of Word.

For example, we want to show the title of this report in the Word document to display: 14 characters, bold, and aligned. First we need to record the corresponding macro command in Word. Open Word, create a new one, manually, select the tool -> macro-> Record new macro command, take a name for the new macro such as Macro1, perform the above action (No. 14 word, bold, center alignment), Word automatically saves these motions to the corresponding VBScript command. Then select the tool -> macro-> macro command, select the macro MacRo1 we defined just before you can view its content. In this case we save the macro command as follows:

Selection.ParagraphFormat.Alignment = WDalignParagraphCenter 'aligned selection.font.bold = wdtoggle' bold display selection.font.size = 14 '14 word

Because the macro's scripting language is VBScript, we don't need to do any changes, you can use the above statements in VB. In this way, we can write the following VB code to achieve the functions we have requested. code show as below:

WdApp.Selection.Font.Bold = wdToggle 'bold WdApp.Selection.Font.Size = 14 No. '14 word WdApp.Selection.TypeText ( "Report title") "Report title WdApp.Selection.ParagraphFormat.lignment = wdAlignParagraphCenter' Centrifugal WDAPP.SeLection.Font.Bold = WDTogGle 'cancellation

Similarly, if we want to do other processing on the Word document, we can repeat the above steps. The following provides an example of your complete handling of Word documents:

Private function saveasword (byref myrecord as recordset), byval docfilename as string, byref outmessage as string AS integer '******************************* *********************************************** Description: Data Concentration Save As Doc File '' Parameters: '' 'MyRecord Dataset' DocFileName Word file name (no path, path to instance variable spath) 'OutMessage operation return information' 'Return: 1 Success-1 failed " '********************************************************** ************************ 'Initializing Word App Err.clear On Error Goto Err_all Dim Wdapp As Word.Application Set WDAPPPPPPPPPP = CREATEOBJECT ("Word.Application ") 'Insert Data DIM COLLOOP AS INTEGER' List DIM ROWLOOP AS INTEGER 'LAN DIM COLMAX AS INTEGER' Columns DIM ROWMAX AS INTEGER 'Route DIM WDCELL AS INTEGER' Wide DIM United AS Integer 'Intercept End Point DIM UnitName AS String 'unit name DIM bbdate as string' Reports Dimension WDCELL = 12 COLMAX = MyRecord.fields.count RowMax = MyRecord.Recordcount

WDAPP.Documents.add 'Get report unit united = IITNAME = MID (sbbdetail, 1, united - 2) BBDATE = MID (sbbdetail, united, len (sbbdetail) if myRecord.fields. count> = 10 Then WdApp.ActiveDocument.PageSetup.Orientation = wdOrientLandscape Else WdApp.ActiveDocument.PageSetup.Orientation = wdOrientPortrait End If 'report name WdApp.Selection.Font.Bold = wdToggle WdApp.Selection.Font.Size = 14 WdApp.Selection .TypeText (sbbmc) WdApp.Selection.ParagraphFormat.lignment = wdAlignParagraphCenter WdApp.Selection.Font.Bold = wdToggle WdApp.Selection.TypeParagraph 'report name WdApp.Selection.Font.color = wdColorBlack WdApp.Selection.Font.Size = 11 WdApp.Selection.TypeText (UnitName) WdApp.Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter WdApp.Selection.TypeParagraph 'reports of other WdApp.Selection.TypeText (bbDate) WdApp.Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter WdApp.Se Lection.TypeParagraph wdapp.selection.typeparagraph 'generated list' wdapp.selection.homekey wdline, wdextend 'dapp.selection.font.bold = wdtoggle

Wdapp.activedocument.tables.Add wdapp.selection.range, RowMax, Colmax Dim i as integer do for colmax = 0 to colmax - 1 wdapp.selection.font.size = 9 if i = 0 Then 'table Title bold display WdApp.Selection.Font.Bold = wdToggle 'table header row background color to gray, gray to 30 With WdApp.Selection.Cells With .Shading .Texture = wdTextureNone .ForegroundPatternColor = wdColorAutomatic .BackgroundPatternColor = wdColorGray30 End With End With End If 'Last line right alignment, the remaining left align IF i> 0 THEN IF MyRecord.fields.item (colloop) .name = "zbmc" or myrecord.fields.item (colloop) .Name = "indicator name" THEN WDAPP.SELECTION. ParagraphFormat.Alignment = wdalignparagraphleft else wdapp.selection.paragraph Format.Alignment = wdalignparagraphright end if End if I = 0 and (myRecord.fields.Item (colloop) .name = "SX" or myRecord.fields.Item (colloop) .Name = "sequence number") THEN WDAPP.SELECTION .Typetext ("serial number) Else Wdapp.selection.typetext (cstr (MyRecord.fields.Item (Colloop)) End ififf (i <> rowmax - 1 or (i = rowmax - 1 and colloop

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

New Post(0)