/home/mjc1/public_html/manage/writeexcel/example-textwrap.php


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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php

require_once "class.writeexcel_workbook.inc.php";
require_once 
"class.writeexcel_worksheet.inc.php";

$fname tempnam("/tmp""textwrap.xls");
$workbook = &new writeexcel_workbook($fname);
$worksheet = &$workbook->addworksheet();

# Set the column width for columns 1, 2 and 3
$worksheet->set_column(1124);
$worksheet->set_column(2234);
$worksheet->set_column(3334);

# Set the row height for rows 1, 4, and 6. The heigt of row 2 will adjust
# automatically to fit the text.
#
$worksheet->set_row(030);
$worksheet->set_row(340);
$worksheet->set_row(580);

# No newlines
$str1  "For whatever we lose (like a you or a me) ";
$str1 .= "it's always ourselves we find in the sea";

# Embedded newlines
$str2  "For whatever we lose\n(like a you or a me)\n";
$str2 .= "it's always ourselves\nwe find in the sea";


# Create a format for the column headings
$header =& $workbook->addformat();
$header->set_bold();
$header->set_font("Courier New");
$header->set_align('center');
$header->set_align('vcenter');

# Create a "vertical justification" format
$format1 =& $workbook->addformat();
$format1->set_align('vjustify');

# Create a "text wrap" format
$format2 =& $workbook->addformat();
$format2->set_text_wrap();

# Write the headers
$worksheet->write(01"set_align('vjustify')"$header);
$worksheet->write(02"set_align('vjustify')"$header);
$worksheet->write(03"set_text_wrap()"$header);

# Write some examples
$worksheet->write(11$str1$format1);
$worksheet->write(12$str1$format1);
$worksheet->write(13$str2$format2);

$worksheet->write(31$str1$format1);
$worksheet->write(32$str1$format1);
$worksheet->write(33$str2$format2);

$worksheet->write(51$str1$format1);
$worksheet->write(52$str1$format1);
$worksheet->write(53$str2$format2);

$workbook->close();

header("Content-Type: application/x-msexcel; name=\"example-textwrap.xls\"");
header("Content-Disposition: inline; filename=\"example-textwrap.xls\"");
$fh=fopen($fname"rb");
fpassthru($fh);
unlink($fname);

?>