word reporting...or dynamic reporting....
I have a code for word reporting in vb.net as below.but i want this code in c#.net.i have converted it through vb to c# converter,but it didnt work properly...can somebody help me out?
myword = CreateObject("word.application")
mydoc = myword.Documents.Add
myword.Selection.PageSetup.PaperSize = Word.WdPaperSize.wdPaperA4
myword.Selection.PageSetup.Orientation = Word.WdOrientation.wdOrientPortrait
myword.Selection.PageSetup.RightMargin = 10
myword.Selection.PageSetup.TopMargin = 50
myword.Selection.PageSetup.LeftMargin = 50
myword.Selection.PageSetup.BottomMargin = 50
myword.Visible = True
myword.WindowState = Word.WdWindowState.wdWindowStateMaximize
myword.Activate()
myword.Selection.TypeText(newline + newline)
myword.Selection.Font.Bold = True
myword.Selection.Font.Name = "Arial"
myword.Selection.Font.AllCaps.ToString()
myword.Selection.Font.Size = 12
myword.Selection.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter
myword.Selection.TypeText("Company Name" + newline + newline)
myword.Selection.Font.Size = 10
myword.Selection.TypeText(" Available Stock " + newline + newline)
myword.Selection.Font.Underline = Word.WdUnderline.wdUnderlineNone
myword.Selection.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft
Try
query1 = "select ItemId,Item_Name,Quantity,QtyType from ItemMaster "
If con1.State = ConnectionState.Open Then con1.Close()
con1.Open()
cmd = New OleDbCommand(query1, con1)
adp = New OleDbDataAdapter(cmd)
ds = New DataSet
adp.Fill(ds)
Dim s As Integer = ds.Tables(0).Rows.Count + 1
Dim t As Integer = 2
dr1 = cmd.ExecuteReader()
myword.Selection.Font.Bold = False
mytable = myword.Selection.Tables.Add(myword.Selection.Range, s, 3)
mycols = mytable.Columns
mytable.Borders.Enable = True
mycell = mytable.Cell(1, 1) : mycell.Select()
myword.Selection.Font.Bold = True
mycell.SetWidth(200, Word.WdRulerStyle.wdAdjustSameWidth)
myword.Selection.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter
myword.Selection.TypeText("Item_Name")
mycell = mytable.Cell(1, 2) : mycell.Select()
myword.Selection.Font.Bold = True
mycell.SetWidth(100, Word.WdRulerStyle.wdAdjustSameWidth)
myword.Selection.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter
myword.Selection.TypeText("Quantity")
mycell = mytable.Cell(1, 3) : mycell.Select()
myword.Selection.Font.Bold = True
mycell.SetWidth(100, Word.WdRulerStyle.wdAdjustSameWidth)
myword.Selection.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter
myword.Selection.TypeText("Type")
While dr1.Read
If t <= s Then
mycell = mytable.Cell(t, 1) : mycell.Select()
mycell.SetWidth(200, Word.WdRulerStyle.wdAdjustSameWidth)
myword.Selection.TypeText(IIf(IsDBNull(dr1.Item(1)), "-", dr1.Item(1)))
mycell = mytable.Cell(t, 2) : mycell.Select()
mycell.SetWidth(100, Word.WdRulerStyle.wdAdjustSameWidth)
myword.Selection.TypeText(IIf(IsDBNull(dr1.Item(2)), "-", dr1.Item(2)))
mycell = mytable.Cell(t, 3) : mycell.Select()
mycell.SetWidth(100, Word.WdRulerStyle.wdAdjustSameWidth)
myword.Selection.TypeText(IIf(IsDBNull(dr1.Item(3)), "-", dr1.Item(3)))
t = t + 1
End If
End While
con1.Close()
Catch e1 As Exception
MsgBox(e1.Message, MsgBoxStyle.Critical, "oledb Error")
End Try