使用 Visual Studio 代码。
Python 3 安装在本地。
存储在服务器上的工作文件。
我正在使用 pandasExcelWriter
来修改 excel 文件。
如果ExcelWriter
指向本地路径,那么它工作正常,
writer = pd.ExcelWriter('C:\\Users\\username\\Documents\\TestingFolder\\ExpirationList.xlsx')
但如果我将它指向一个服务器位置,那么它会给我一个错误:
FileNotFoundError: [Errno 2] No such file or directory: '\\01.02.03.04\\username\\Documents\\Documents\\Python\\"Expiration List report email send out"\\ExpirationList.xlsx'
示例代码:
import pandas as pd
import pyodbc
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
import datetime
import calendar
query = """select top 5 PolicyNumber from tblQuotes where PolicyNumber is not null"""
conn = pyodbc.connect('DRIVER={SQL Server};server=servername;DATABASE=dbName;Trusted_Connection=yes;')
df = pd.read_sql_query(query, conn)
writer = pd.ExcelWriter('C:\\Users\\username\\Documents\\TestingFolder\\ExpirationList.xlsx')
#Does not work
writer = pd.ExcelWriter('\\01.02.03.04\\username\\Documents\\Documents\\Python\\"Expiration List report email send out"\\ExpirationList.xlsx')
df.to_excel(writer, sheet_name='Sheet1', startrow=4, header=False, index=False)
writer.save()
使用服务器位置的方法是什么?