אוטומציה WORD
כמובטח עוד שאלה: יש לי אוטומציית WORD שעובדת בפרויקט WINFORM (פותח מסמך ויוצרת בו טבלה וממלאת אותה מהבסיס נתונים). אותו הקוד אינו עובד משום מה בפרויקט WEBFORM. שינינו את ההרשאה בעקבות המלצתכם, והוא לא עף הפעם, אך גם לא נפתח (ה-VISIBLE שלו TRUE). ניתן לראות שהמסמך קיים דרך ה-TASK MANAGER אך לא ניתן לראות את המסמך. הקוד:
Sub CreateWordAtt(ByVal OrderNO As Integer) Dim wrdApp As Word.ApplicationClass = New Word.ApplicationClass Dim wrdSelection As Word.Selection Dim wrdDoc As Word._Document '= wrdApp.Documents.Add(dotFileStr) Dim StrToAdd As String Dim ProductOrderCustRow As DsMakolet.product_orderRow Dim ProductOrderCustDataTable As DsMakolet.product_orderDataTable = MakoletDataSet.product_order MakoletDataSet.product_order.Clear() ProductOrdersCustDataAdapter.SelectCommand.Parameters("customer").Value = Session("Login") ProductOrdersCustDataAdapter.SelectCommand.Parameters("orders").Value = OrderNO 'current order parameter for the query uses the admin order ProductOrdersCustDataAdapter.Fill(MakoletDataSet.product_order) Dim ProdName, Details, CompName, Price, Unit, Amount, Total As String Dim i, j As Integer Try ' Create an instance of Word and make it visible. wrdApp.Visible = True ' Add a new document. wrdDoc = wrdApp.Documents.Add() wrdDoc.Select() wrdSelection = wrdApp.Selection() 'bold font on wrdSelection.Font.Bold = True 'underline on If wrdSelection.Font.Underline = False Then wrdSelection.Font.Underline = True Else wrdSelection.Font.Underline = False End If ' Create a string and insert it in the document. StrToAdd = "הזמנה מספר: " & OrderNO & vbCr & _ "רשימת המוצרים שרכשת:" wrdSelection.ParagraphFormat.Alignment = _ Word.WdParagraphAlignment.wdAlignParagraphCenter wrdSelection.TypeText(StrToAdd) 'underline off If wrdSelection.Font.Underline = False Then wrdSelection.Font.Underline = True Else wrdSelection.Font.Underline = False End If 'bold font off wrdSelection.Font.Bold = False 'Insert blank lines. wrdApp.Selection.TypeParagraph() wrdApp.Selection.TypeParagraph() wrdSelection.ParagraphFormat.Alignment = _ Word.WdParagraphAlignment.wdAlignParagraphRight ' Insert a new table with 9 rows and 4 columns. wrdDoc.Tables.Add(wrdSelection.Range, NumRows:=ProductOrderCustDataTable.Count + 1, _ NumColumns:=7) With wrdDoc.Tables.Item(1) ' Set the column widths. .Columns.Item(1).SetWidth(70, Word.WdRulerStyle.wdAdjustNone) .Columns.Item(2).SetWidth(90, Word.WdRulerStyle.wdAdjustNone) .Columns.Item(3).SetWidth(70, Word.WdRulerStyle.wdAdjustNone) .Columns.Item(4).SetWidth(50, Word.WdRulerStyle.wdAdjustNone) .Columns.Item(5).SetWidth(50, Word.WdRulerStyle.wdAdjustNone) .Columns.Item(6).SetWidth(30, Word.WdRulerStyle.wdAdjustNone) .Columns.Item(7).SetWidth(50, Word.WdRulerStyle.wdAdjustNone) 'Set the shading on the first row to light gray. .Rows.Item(1).Cells.Shading.BackgroundPatternColorIndex = _ Word.WdColorIndex.wdGray25 'Bold the first row. .Rows.Item(1).Range.Bold = True 'Center the text in row 1. For j = 1 To j <= 7 .Cell(1, j).Range.Paragraphs.Alignment = _ Word.WdParagraphAlignment.wdAlignParagraphCenter Next ' Fill each row of the table with data. FillRow(wrdDoc, 1, "שם", "פרטים", "חברה", "מחיר", "יחידה", "כמות", "סך") i = 1 For Each ProductOrderCustRow In ProductOrderCustDataTable &