Public Sub CreatDoc(ByVal titlestr As String, ByVal ds As DataSet, ByVal fn As String, ByVal StartDate As Date, ByVal EndDate As Date, Optional ByVal DayReport As Integer = 0)
'Instantiate a Pdf instance
Dim doc1 As Aspose.Words.Document = New Aspose.Words.Document
Dim builder As New Aspose.Words.DocumentBuilder(doc1)
builder.Write(titlestr)
builder.InsertBreak(Aspose.Words.BreakType.ParagraphBreak)
builder.InsertBreak(Aspose.Words.BreakType.ParagraphBreak)
For i As Integer = 0 To ds1.Tables.Count - 1
If ds1.Tables(i).Rows.Count > 0 Then
If i = 4 Then
builder.MoveToDocumentEnd()
builder.InsertBreak(Aspose.Words.BreakType.PageBreak)
'Chart图片
Select Case DayReport
Case 0
doc1 = InsertImg2Doc(doc1, StartDate, EndDate, "小时", 3)
'sec2 = InsertImg2Pdf(sec2, StartDate, EndDate, "小时", 3)
Case 1
doc1 = InsertImg2Doc(doc1, StartDate, EndDate, "天", 10)
'sec2 = InsertImg2Pdf(sec2, StartDate, EndDate, "天", 10)
Case 2
doc1 = InsertImg2Doc(doc1, StartDate, EndDate, "天", 10)
doc1 = InsertImg2Doc(doc1, StartDate, EndDate, "周", 10)
'sec2 = InsertImg2Pdf(sec2, StartDate, EndDate, "天", 10)
'sec2 = InsertImg2Pdf(sec2, StartDate, EndDate, "周", 10)
End Select
builder.MoveToDocumentEnd()
builder.InsertBreak(Aspose.Words.BreakType.PageBreak)
End If
doc1 = InsertTable2Doc(doc1, ds1.Tables(i))
End If
Next
ds1.Dispose()
doc1.Save(fn)
End Sub
Private Function InsertTable2Doc(ByVal doc1 As Aspose.Words.Document, ByVal tb As DataTable) As Aspose.Words.Document
Dim builder As New Aspose.Words.DocumentBuilder(doc1)
builder.MoveToDocumentEnd()
builder.StartTable()
builder.Write(tb.TableName)
'
头
For i As Integer = 0 To tb.Columns.Count - 1
builder.InsertCell()
builder.Write(tb.Columns(i).ColumnName)
Next
builder.EndRow()
For i As Integer = 0 To tb.Rows.Count - 1
For j As Integer = 0 To tb.Columns.Count - 1
builder.InsertCell()
builder.Write(tb.Rows(i)(j).ToString)
Next
builder.EndRow()
Next
builder.EndTable()
builder.InsertBreak(Aspose.Words.BreakType.ParagraphBreak)
Return doc1
End Function
Function InsertImg2Doc(ByVal doc1 As Aspose.Words.Document, ByVal startdate As Date,
ByVal enddate As Date, ByVal type1 As String, ByVal ChartType As Integer,
Optional ByVal Enable3D As Boolean = True) As Aspose.Words.Document
Dim builder As New Aspose.Words.DocumentBuilder(doc1)
builder.MoveToDocumentEnd()
builder.Write("按" & type1 & "浏览量:")
Dim dt As DataTable = stat1.StatByDate(type1, "", startdate, enddate)
Dim mychart As System.Windows.Forms.DataVisualization.Charting.Chart = stat1.ShowChart1(dt, ChartType, "浏览量", type1, Enable3D)
'mychart.Series(0).ChartType = DataVisualization.Charting.SeriesChartType.Column
'初始化数值
mychart.Width = doc1.GetPageInfo(0).WidthInPoints - 40
mychart.Height = 300
mychart.Series(0).Name = "浏览量"
Dim ms As MemoryStream = New MemoryStream()
mychart.SaveImage(ms, System.Drawing.Imaging.ImageFormat.Png)
'mychart.Dispose()
Dim image1 As Aspose.Pdf.Generator.Image = New Aspose.Pdf.Generator.Image()
image1.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.Png
'image1.ImageInfo.ImageStream = ScaleImg(ms, sec2.PageInfo.PageWidth, 0)
image1.ImageInfo.ImageStream = ms
builder.InsertImage(ms)
Return doc1
End Function
文档已经阅读完毕,请返回上一页!