powerbuilder excel 导出代码
时间: 2023-05-28 22:08:05 浏览: 344
以下是使用PowerBuilder导出Excel文件的示例代码:
1. 定义变量和常量
```
string ls_path, ls_file, ls_title, ls_tablename
long ll_row, ll_col, ll_sheet
oleobject lole_excel
```
2. 打开Excel应用程序
```
lole_excel = create oleobject
lole_excel.connecttonewobject("excel.application")
```
3. 创建工作簿和工作表
```
lole_excel.workbooks.add()
ll_sheet = 1
lole_excel.worksheets[ll_sheet].activate()
```
4. 设置Excel单元格格式
```
lole_excel.cells[1,1].font.bold = true
lole_excel.cells[1,1].font.size = 12
lole_excel.cells[1,1].value = ls_title
lole_excel.cells[1,1].entirecolumn.autofit()
```
5. 导出数据到Excel
```
for ll_col = 1 to dw_1.object.datawindow.column.count()
lole_excel.cells[2,ll_col].value = dw_1.object.datawindow.column[ll_col].name
lole_excel.cells[2,ll_col].font.bold = true
lole_excel.cells[2,ll_col].font.size = 10
lole_excel.cells[2,ll_col].entirecolumn.autofit()
next
for ll_row = 1 to dw_1.object.datawindow.rowcount()
for ll_col = 1 to dw_1.object.datawindow.column.count()
lole_excel.cells[ll_row+2,ll_col].value = dw_1.object.datawindow.getitemstring(ll_row,ll_col)
lole_excel.cells[ll_row+2,ll_col].font.size = 10
lole_excel.cells[ll_row+2,ll_col].entirecolumn.autofit()
next
next
```
6. 保存Excel文件并关闭
```
ls_file = "D:\test.xls"
lole_excel.activeworkbook.saveas(ls_file)
lole_excel.activeworkbook.close()
lole_excel.disconnectobject()
```
以上是一个简单的PowerBuilder导出Excel文件的示例代码。您可以根据自己的需要进行修改和优化。
阅读全文