3

I am trying to move a column of data (mean values) from a dbf file to an excel spreadsheet. I have been trying this with Wing IDE with no success so far. I am not a progamming student and this is a short term assignment. I am stuck on the part where I have to retrieve the file from the specific network drive and copy the data onto my local excel sheet. Help would be great. Thanks

4

2 回答 2

3

你需要Python Excel工具,我也会推荐我自己的dbf 包

import dbf
import xlwt

dbf_files = ('file1.dbf','file2.dbf','file3.dbf')

output_xls = xlwt.Workbook()
sheet = output_xls.add_sheet('sheet_name')

for i, filename in enumerate(dbf_files):
    total = 0
    with dbf.Table(filename) as table:
        for record in table:
            total += record.some_count   # some_count being a field name in the dbf files
    sheet.write(i, 0, filename)
    sheet.write(i, 1, total)

output_xls.save('final.xls')

希望这能让您了解如何处理您的用例。如果您有任何问题,请告诉我。

于 2012-08-22T12:52:29.857 回答
1

据我了解,您可以将 ADODB 与 Python 一起使用。您可以针对连接运行查询以从 DBF 插入 Excel 文件。

这适用于VBA,希望你能翻译。

strCon = "Provider=Microsoft.ACE.OLEDB.12.0;" _
  & "Data Source=z:\docs\myexcel.xlsm;Extended Properties=""Excel 8.0;HDR=No"";"

Set cn = CreateObject("ADODB.Connection")
cn.Open strCon

strsql = "SELECT * INTO [mynewsheet] " _
  & "FROM [dBASE III;DATABASE=z:\docs\].[mydbf.dbf] "
  cn.Execute strsql
于 2012-08-17T16:34:51.603 回答