目前想要导出单元格的背景图片,通过直接导出PDF无法导出,通过 PrintBackground 方法可以绘制背景图片,但是这个方法绘制的背景图片在每一页都有,想问下老师能不能在每一页都绘制不同的背景图片- Private Sub fs_PrintBackground(sender As Object, e As PrintBackgroundEventArgs) Handles fs.PrintBackground
- fs.ActiveSheet.FrozenRowCount = 0
- Dim saveState As System.Drawing.Drawing2D.GraphicsState = e.Graphics.Save()
- Width = 0
- If fs.ActiveSheet.RowCount > 0 Then
- For i As Integer = 0 To fs.ActiveSheet.ColumnCount - 1
- Width += fs.ActiveSheet.GetColumnWidth(i)
- Next
- End If
- For i As Integer = 0 To fs.ActiveSheet.RowCount - 1
- If TypeName(fs.ActiveSheet.Cells(i, 0).CellType).Equals("TextCellType") Then
- Dim cellType As TextCellType = fs.ActiveSheet.Cells(i, 0).CellType()
- If cellType.BackgroundImage IsNot Nothing Then
- Dim rt As Rectangle = fs.GetCellRectangle(0, 0, i, 0)
- rt.Height = fs.ActiveSheet.Rows(i).Height
- rt.Width = cellType.BackgroundImage.Image.Width * (fs.ActiveSheet.Rows(i).Height / cellType.BackgroundImage.Image.Height)
- rt.X = (Width - rt.Width) / 2
- e.Graphics.SetClip(rt)
- e.Graphics.DrawImage(cellType.BackgroundImage.Image, rt)
- End If
- End If
- Next
- e.Graphics.Restore(saveState)
- End Sub
复制代码
|
|