接上:
Public Sub SetCellProperty(ByVal wsn As String,Endy)).HorizontalAlignment = HorizontalAlignment
End Sub
Public Sub UniteCells(ByVal ws As Excel.Worksheet,ByVal x1 As Integer,ByVal y1 As Integer,ByVal x2 As Integer,ByVal y2 As Integer)
'合并单元格
ws.get_Range(ws.Cells(x1,y1),ws.Cells(x2,y2)).Merge(Type.Missing)
End Sub
Public Sub UniteCells(ByVal ws As String,ByVal y2 As Integer)
'合并单元格
GetSheet(ws).get_Range(GetSheet(ws).Cells(x1,GetSheet(ws).Cells(x2,y2)).Merge(Type.Missing)
End Sub
Public Sub InsertTable(ByVal dt As System.Data.DataTable,ByVal ws As String,ByVal startX As Integer,ByVal startY As Integer)
'将内存中数据表格插入到Excel指定工作表的指定位置 为在使用模板时控制格式时使用一
For i As Integer = 0 To dt.Rows.Count - 1
For j As Integer = 0 To dt.Columns.Count - 1
GetSheet(ws).Cells(startX + i,j + startY) = dt.Rows(i)(j).ToString()
Next
Next
End Sub
Public Sub InsertTable(ByVal dt As System.Data.DataTable,ByVal ws As Excel.Worksheet,ByVal startY As Integer)
'将内存中数据表格插入到Excel指定工作表的指定位置二
For i As Integer = 0 To dt.Rows.Count - 1
For j As Integer = 0 To dt.Columns.Count - 1
ws.Cells(startX + i,j + startY) = dt.Rows(i)(j)
Next
Next
End Sub
Public Sub AddTable(ByVal dt As System.Data.DataTable,ByVal startY As Integer)
'将内存中数据表格
添加到Excel指定工作表的指定位置一
For i As Integer = 0 To dt.Rows.Count - 1
For j As Integer = 0 To dt.Columns.Count - 1
GetSheet(ws).Cells(i + startX,j + startY) = dt.Rows(i)(j)
Next
Next
End Sub
Public Sub AddTable(ByVal dt As System.Data.DataTable,ByVal startY As Integer)
'将内存中数据表格
添加到Excel指定工作表的指定位置二
For i As Integer = 0 To dt.Rows.Count - 1
For j As Integer = 0 To dt.Columns.Count - 1
ws.Cells(i + startX,j + startY) = dt.Rows(i)(j)
Next
Next
End Sub
Public Sub InsertPictures(ByVal Filename As String,ByVal ws As String)
'插入
图片操作一
GetSheet(ws).Shapes.AddPicture(Filename,MsoTriState.msoFalse,MsoTriState.msoTrue,10,150,_
150)
'后面的数字表示位置
End Sub
'public void InsertPictures(string Filename,string ws,int Height,int Width)//插入
图片操作二
'{
' GetSheet(ws).Shapes.AddPicture(Filename,150);
' GetSheet(ws).Shapes.get_Range(Type.Missing).Height = Height;
' GetSheet(ws).Shapes.get_Range(Type.Missing).Width = Width;
'}
'public void InsertPictures(string Filename,int left,int top,int Width)//插入
图片操作三
'{
' GetSheet(ws).Shapes.AddPicture(Filename,150);
' GetSheet(ws).Shapes.get_Range(Type.Missing).IncrementLeft(left);
' GetSheet(ws).Shapes.get_Range(Type.Missing).IncrementTop(top);
' GetSheet(ws).Shapes.get_Range(Type.Missing).Height = Height;
' GetSheet(ws).Shapes.get_Range(Type.Missing).Width = Width;
'}
Public Sub InsertActiveChart(ByVal ChartType As Excel.XlChartType,ByVal DataSourcesX1 As Integer,ByVal DataSourcesY1 As Integer,ByVal DataSourcesX2 As Integer,ByVal DataSourcesY2 As Integer,_
ByVal ChartDataType As Excel.XlRowCol)
'插入图表操作
ChartDataType = Excel.XlRowCol.xlColumns
wb.Charts.Add(Type.Missing,Type.Missing)
wb.ActiveChart.ChartType = ChartType
wb.ActiveChart.SetSourceData(GetSheet(ws).get_Range(GetSheet(ws).Cells(DataSourcesX1,DataSourcesY1),GetSheet(ws).Cells(DataSourcesX2,DataSourcesY2)),ChartDataType)
wb.ActiveChart.Location(Excel.XlChartLocation.xlLocationAsObject,ws)
End Sub
Public Function Save() As Boolean
'保存文档
If mFilename = "" Then
Return False
Else
Try
wb.Save()
Return True
Catch ex As Exception
Return False
End Try
End If
End Function
Public Function SaveAs(ByVal FileName As Object) As Boolean
'文档另存为
Try
wb.SaveAs(FileName,_
Excel.XlSaveAsAccessMode.xlExclusive,Type.Missing)
Return True
Catch ex As Exception
Return False
End Try
End Function
Public Sub Close()
'
关闭一个Excel对象,销毁对象
'wb.Save();
wb.Close(Type.Missing,Type.Missing)
wbs.Close()
app.Quit()
wb = Nothing
wbs = Nothing
app = Nothing
GC.Collect()
End Sub
End Class
End Namespace