pb中调用excel生成图片在这里:http://www.tiantiansoft.com/bbs/dispbbs.asp?BoardID=3&ID=106960
设了窗口的全局变量:OLEObject ole_object,ole_workbooks,一些函数在下边
/*
uf_getname 取保存excel的文件路径
*/
integer li_rc
string ls_path,ls_file
li_rc = GetFileSaveName ("文件保存路径", ls_path, ls_file,".xls","EXCEL文件(*.xls),*.xls","c:\",32770)
if li_rc=0 then
return "" //取消
elseif li_rc<>1 then
messagebox('系统提示','文件读写出错,保存失败')
return ""
end if
return ls_path
/*
uf_workbook 创建对象连接excel,还要生成一个工作表
返回true 生成成功
返回false 生成失败
*/
//建立OLEObject对象
ole_object=CREATE OLEObject
//IF ole_object.ConnectToObject(ls_path)<>0 THEN
if ole_object.ConnectToNewObject("Excel.Application")<>0 then
MessageBox('OLE错误','OLE无法连接!请确定已经安装EXCEL!')
return false
END IF
//添加工作表
ole_object.Workbooks.Add //创建包含一定数目的空白工作表的工作簿
ole_object.visible=true
ole_workbooks=ole_object.worksheets(1)
return true
/*
uf_save 保存excel文件,并释放ole对象
*/
//保存
ole_workbooks.saveas(ls_path)
Ole_Object.save()
//释放
Ole_Object.DisConnectObject()
Destroy Ole_Object
destroy ole_workbooks
/*
uf_all 设置整个文档都是宋体9号字
*/
ole_workbooks.Cells.Font.Name = "宋体"
ole_workbooks.Cells.Font.Size = 9
ole_workbooks.Cells.Font.Strikethrough = False
ole_workbooks.Cells.Font.Superscript = False
ole_workbooks.Cells.Font.Subscript = False
ole_workbooks.Cells.Font.OutlineFont = False
ole_workbooks.Cells.Font.Shadow = False
ole_workbooks.Cells.Font.Underline = -4142 //xlUnderlineStyleNone
ole_workbooks.Cells.Font.ColorIndex = -4105 //xlAutomatic
/*
uf_align 设置excel里单元格属性的对齐标签,成用来合并单元格
string ar_range 选中的单元格,比如"A1:F1"
string ar_h HorizontalAlignment属性,就是文字横向对齐
string ar_v VerticalAlignment属性,就是文字的纵向对齐
boolean ar_mergecells MergeCells属性,就是单元格要没要合并
*/
//ole_workbooks.Range(ar_range).Select
ole_workbooks.Range(ar_range).HorizontalAlignment = uf_align_num(ar_h)
ole_workbooks.Range(ar_range).VerticalAlignment = uf_align_num(ar_v)
ole_workbooks.Range(ar_range).WrapText = False
ole_workbooks.Range(ar_range).Orientation = 0
ole_workbooks.Range(ar_range).AddIndent = False
ole_workbooks.Range(ar_range).IndentLevel = 0
ole_workbooks.Range(ar_range).ShrinkToFit = False
ole_workbooks.Range(ar_range).ReadingOrder = -5002 //xlContext
//单元格是否合并
ole_workbooks.Range(ar_range).MergeCells = ar_MergeCells
其中uf_align_num函数用来返回枚举变量对应的数值
/*
integer uf_align_num 返回枚举变量对应的数值
string ar_align 枚举变量
*/
integer align
choose case ar_align
case "xlRight"
align = -4152
case "xlLeft"
align = -4131
case "xlCenter"
align = -4108
case "xlGeneral"
align = 1
case else
align = 1
end choose
return align
//设置第二列的宽度
ole_workbooks.Columns("B:B").ColumnWidth = 44.38
//设置第二列自动换行
//ole_workbooks.Columns("B:B").Select
ole_workbooks.Columns("B:B").HorizontalAlignment = 1 //xlGeneral
ole_workbooks.Columns("B:B").VerticalAlignment = 2 //1,垂直居上 2,xlCenter 3,垂直居下
ole_workbooks.Columns("B:B").WrapText = True
ole_workbooks.Columns("B:B").Orientation = 0
ole_workbooks.Columns("B:B").AddIndent = False
ole_workbooks.Columns("B:B").IndentLevel = 0
ole_workbooks.Columns("B:B").ShrinkToFit = False
ole_workbooks.Columns("B:B").ReadingOrder = -5002 //xlContext
ole_workbooks.Columns("B:B").MergeCells = False
//设置B8的格式是日期
ole_workbooks.Range("B8").NumberFormatLocal = "yyyy-m-d"
uf_align("B8","xlLeft","xlCenter",false)
//把值ar_word插入第ar_row第ar_col的单元格里
ole_workbooks.cells(ar_row,ar_col).value="/ar_word
//插入图片
ole_workbooks.Pictures.Insert(ls_path)
//指定高度缩放,按比例缩放,就是“设置图片格式”->“大小”
ole_workbooks.Shapes(1).LockAspectRatio" = -1
ole_workbooks.Shapes(1).Height = 108
ole_workbooks.Shapes(1).Rotation = 0
/*
uf_font 设置excel里单元格属性的字体标签
string ar_range 选中的单元格
string ar_font 字体
string ar_style 字体的方式("常规"、"斜体"、"粗体"、"加粗 倾斜")
integer ar_size 字体大小
*/
ole_workbooks.Range(ar_range).Font.Name = ar_font
ole_workbooks.Range(ar_range).Font.FontStyle = ar_style
ole_workbooks.Range(ar_range).Font.Size = ar_size
ole_workbooks.Range(ar_range).Font.Strikethrough = False
ole_workbooks.Range(ar_range).Font.Superscript = False
ole_workbooks.Range(ar_range).Font.Subscript = False
ole_workbooks.Range(ar_range).Font.OutlineFont = False
ole_workbooks.Range(ar_range).Font.Shadow = False
ole_workbooks.Range(ar_range).Font.Underline = -4142//xlUnderlineStyleNone
ole_workbooks.Range(ar_range).Font.ColorIndex = -4105//xlAutomatic