|
| 1 | +---- |
| 2 | +-- |
| 3 | +-- Example of how to use the xlsxwriter.lua module to write hyperlinks. |
| 4 | +-- |
| 5 | +-- Copyright 2014, John McNamara, [email protected] |
| 6 | +-- |
| 7 | + |
| 8 | +local Workbook = require "xlsxwriter.workbook" |
| 9 | + |
| 10 | +local workbook = Workbook:new("hyperlink.xlsx") |
| 11 | +local worksheet = workbook:add_worksheet("Hyperlinks") |
| 12 | + |
| 13 | +-- Format the first column |
| 14 | +worksheet:set_column('A:A', 30) |
| 15 | + |
| 16 | +-- Add the standard url link format. |
| 17 | +local url_format = workbook:add_format({ |
| 18 | + font_color = 'blue', |
| 19 | + underline = 1 |
| 20 | +}) |
| 21 | + |
| 22 | +-- Add a sample alternative link format. |
| 23 | +local red_format = workbook:add_format({ |
| 24 | + font_color = 'red', |
| 25 | + bold = 1, |
| 26 | + underline = 1, |
| 27 | + font_size = 12, |
| 28 | +}) |
| 29 | + |
| 30 | +-- Add an alternate description string to the URL. |
| 31 | +local alt_string = 'Lua home' |
| 32 | + |
| 33 | +-- Add a "tool tip" to the URL. |
| 34 | +local tip_string = 'Get the latest Lua news here.' |
| 35 | + |
| 36 | +-- Write some hyperlinks |
| 37 | +worksheet:write_url('A1', 'http://www.lua.org/', url_format) |
| 38 | +worksheet:write_url('A3', 'http://www.lua.org/', url_format, alt_string) |
| 39 | +worksheet:write_url('A5', 'http://www.lua.org/', url_format, alt_string, tip_string) |
| 40 | +worksheet:write_url('A7', 'http://www.lua.org/', red_format) |
| 41 | +worksheet:write_url('A9', 'mailto:jmcnamaracpan.org', url_format, 'Mail me') |
| 42 | + |
| 43 | +-- Write a URL that isn't a hyperlink |
| 44 | +worksheet:write_string('A11', 'http://www.lua.org/') |
| 45 | + |
| 46 | +workbook:close() |
0 commit comments