小编Rym*_*Rym的帖子

将unicode字符串写入Excel 2007

我正在使用连接到MS SQL服务器pyodbc.此外,我正在尝试使用写入Excel 2007/10 .xlsx文件openpyxl.

这是我的代码(Python 2.7):

import pyodbc
from openpyxl import Workbook

cnxn = pyodbc.connect(host = 'xxx',database='yyy',user='zzz',password='ppp')
cursor = cnxn.cursor()

sql = "SELECT TOP 10   [customer clientcode] AS Customer, \
                [customer dchl] AS DChl, \
                [customer name] AS Name, \
                ...
                [name3] AS [name 3] \
        FROM   mydb \
        WHERE [customer dchl] = '03' \
        ORDER BY [customer id] ASC"

#load data
cursor.execute(sql)

#get colnames from openpyxl
columns = [column[0] for column in cursor.description]    

#using …
Run Code Online (Sandbox Code Playgroud)

python unicode excel pyodbc openpyxl

7
推荐指数
1
解决办法
4377
查看次数

标签 统计

excel ×1

openpyxl ×1

pyodbc ×1

python ×1

unicode ×1