-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathautofit.rb
executable file
·37 lines (29 loc) · 933 Bytes
/
autofit.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
#
# An example of using simulated autofit to automatically adjust the width of
# worksheet columns based on the data in the cells.
#
# Copyright 2000-2023, John McNamara, [email protected]
#
# SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later
#
# convert to Ruby by Hideo NAKAMURA, [email protected]
#
require 'write_xlsx'
workbook = WriteXLSX.new('autofit.xlsx')
worksheet = workbook.add_worksheet
# Write some worksheet data to demonstrate autofitting.
worksheet.write(0, 0, "Foo")
worksheet.write(1, 0, "Food")
worksheet.write(2, 0, "Foody")
worksheet.write(3, 0, "Froody")
worksheet.write(0, 1, 12345)
worksheet.write(1, 1, 12345678)
worksheet.write(2, 1, 12345)
worksheet.write(0, 2, "Some longer text")
worksheet.write(0, 3, 'http://www.google.com')
worksheet.write(1, 3, 'https://github.com')
# Autofit the worksheet
worksheet.autofit
workbook.close