Python 在同一工作簿中的工作表之间创建超链接
下面的代码创建了一个超链接,但每当我点击该超链接时,它就会显示“无法打开指定的文件”Python 在同一工作簿中的工作表之间创建超链接,python,excel,python-2.7,hyperlink,Python,Excel,Python 2.7,Hyperlink,下面的代码创建了一个超链接,但每当我点击该超链接时,它就会显示“无法打开指定的文件” 我无法测试它,因为我的办公机器上没有安装Python,但我认为类似的东西应该可以帮到你 import xlsxwriter # Create a new workbook and add a worksheet workbook = xlsxwriter.Workbook('hyperlink.xlsx') worksheet = workbook.add_worksheet('Hyperlinks') #
我无法测试它,因为我的办公机器上没有安装Python,但我认为类似的东西应该可以帮到你
import xlsxwriter
# Create a new workbook and add a worksheet
workbook = xlsxwriter.Workbook('hyperlink.xlsx')
worksheet = workbook.add_worksheet('Hyperlinks')
# Format the first column
worksheet.set_column('A:A', 30)
# Add the standard url link format.
url_format = workbook.add_format({
'font_color': 'blue',
'underline': 1
})
# Add a sample alternative link format.
red_format = workbook.add_format({
'font_color': 'red',
'bold': 1,
'underline': 1,
'font_size': 12,
})
# Add an alternate description string to the URL.
string = 'Python home'
# Add a "tool tip" to the URL.
tip = 'Get the latest Python news here.'
# Write some hyperlinks
worksheet.write_url('A1', 'http://www.python.org/') # Implicit format.
worksheet.write_url('A3', 'http://www.python.org/', url_format, string)
worksheet.write_url('A5', 'http://www.python.org/', url_format, string, tip)
worksheet.write_url('A7', 'http://www.python.org/', red_format)
worksheet.write_url('A9', 'mailto:jmcnamara@cpan.org', url_format, 'Mail me')
# Write a URL that isn't a hyperlink
worksheet.write_string('A11', 'http://www.python.org/')
workbook.close()
或者这个
from openpyxl import load_workbook
wb = load_workbook(workbookEx.xlsx)
ws = wb.get_sheet_by_name("sheet1")
link = "workbookEx.xlsx#sheet2!E5"
ws.cell(row=1, column=1).hyperlink = (link)
我无法测试它,因为我的办公机器上没有安装Python,但我认为类似的东西应该可以帮到你
import xlsxwriter
# Create a new workbook and add a worksheet
workbook = xlsxwriter.Workbook('hyperlink.xlsx')
worksheet = workbook.add_worksheet('Hyperlinks')
# Format the first column
worksheet.set_column('A:A', 30)
# Add the standard url link format.
url_format = workbook.add_format({
'font_color': 'blue',
'underline': 1
})
# Add a sample alternative link format.
red_format = workbook.add_format({
'font_color': 'red',
'bold': 1,
'underline': 1,
'font_size': 12,
})
# Add an alternate description string to the URL.
string = 'Python home'
# Add a "tool tip" to the URL.
tip = 'Get the latest Python news here.'
# Write some hyperlinks
worksheet.write_url('A1', 'http://www.python.org/') # Implicit format.
worksheet.write_url('A3', 'http://www.python.org/', url_format, string)
worksheet.write_url('A5', 'http://www.python.org/', url_format, string, tip)
worksheet.write_url('A7', 'http://www.python.org/', red_format)
worksheet.write_url('A9', 'mailto:jmcnamara@cpan.org', url_format, 'Mail me')
# Write a URL that isn't a hyperlink
worksheet.write_string('A11', 'http://www.python.org/')
workbook.close()
或者这个
from openpyxl import load_workbook
wb = load_workbook(workbookEx.xlsx)
ws = wb.get_sheet_by_name("sheet1")
link = "workbookEx.xlsx#sheet2!E5"
ws.cell(row=1, column=1).hyperlink = (link)