-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformat1.php
110 lines (91 loc) · 4.19 KB
/
format1.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Include the PHPWord.php, all other classes were loaded by an autoloader
require_once 'PHPWord.php';
// Create a new PHPWord Object
$PHPWord = new PHPWord();
// Every element you want to append to the word document is placed in a section. So you need a section:
$section = $PHPWord->createSection();
// After creating a section, you can append elements:
$section->addText('Hello world!');
<?php
function formatDoc()
{
include_once("lib/connection.php");
$sql_stud = $mysqli->query("SELECT * FROM student WHERE p_id='1'");
$sql_proj = $mysqli->query("SELECT * FROM project WHERE id='1'");
$sql_srs = $mysqli->query("SELECT * FROM srsdoc WHERE p_id='1'");
$sql_func = $mysqli->query("SELECT * FROM funcreq WHERE docID='1'");
$sql_nonfunc = $mysqli->query("SELECT * FROM nonfuncreq WHERE docID='1'");
// Include the PHPWord.php, all other classes were loaded by an autoloader
require_once 'PHPWord.php';
// Create a new PHPWord Object
$PHPWord = new PHPWord();
// Every element you want to append to the word document is placed in a section. So you need a section:
$section = $PHPWord->createSection();
$section->addTextBreak(6);
//Cover Page
// You can directly style your text by giving the addText function an array:
$styleFont = array('bold'=>true, 'size'=>40, 'name'=>'Times New Roman');
$styleParagraph = array('align'=>'left', 'spaceAfter'=>100);
$data = $sql_proj->fetch_array();
$section->addText($data['name'], $styleFont, $styleParagraph);
$section->addTextBreak(2);
$styleFont = array('bold'=>false, 'size'=>32, 'name'=>'Times New Roman');
$section->addText('Software Requirements Specification', $styleFont, $styleParagraph);
$section->addTextBreak(9);
$data = $sql_stud->fetch_array();
$styleFont = array('bold'=>false, 'size'=>20, 'name'=>'Times New Roman');
$section->addText($data['name']." ".$data['reg_no'], $styleFont, $styleParagraph);
$section->addPageBreak();
//New page
//Styling header and content
$styleHeadingFont = array('bold'=>true, 'size'=>24, 'name'=>'Times New Roman');
$styleHeadingParagraph = array('align'=>'left', 'spaceAfter'=>100);
$styleContentFont = array('bold'=>false, 'size'=>16, 'name'=>'Times New Roman');
$styleContentParagraph = array('align'=>'both', 'spaceAfter'=>100);
$data = $sql_srs->fetch_array();
$section->addText('Purpose', $styleHeadingFont, $styleHeadingParagraph);
$section->addTextBreak();
$section->addText($data['purpose'], $styleContentFont, $styleContentParagraph);
$section->addTextBreak(6);
$section->addText('Scope', $styleHeadingFont, $styleHeadingParagraph);
$section->addTextBreak();
$section->addText($data['scope'], $styleContentFont, $styleContentParagraph);
$section->addTextBreak(6);
$section->addText('Assumptions and Dependencies', $styleHeadingFont, $styleHeadingParagraph);
$section->addTextBreak();
$section->addText($data['assumptions'], $styleContentFont, $styleContentParagraph);
$section->addTextBreak(6);
$section->addText('References', $styleHeadingFont, $styleHeadingParagraph);
$section->addTextBreak();
$section->addText($data['references'], $styleContentFont, $styleContentParagraph);
$section->addPageBreak();
//New page
$styleSubFont = array('bold'=>false, 'size'=>20, 'name'=>'Times New Roman', 'underline'=>PHPWord_Style_Font::UNDERLINE_SINGLE);
$styleSubParagraph = array('align'=>'both', 'spaceAfter'=>100);
$section->addText('Functional Requirements', $styleHeadingFont, $styleHeadingParagraph);
$section->addTextBreak(3);
while($data = $sql_func->fetch_array())
{
$section->addText($data['type'], $styleSubFont, $styleSubParagraph);
$section->addTextBreak();
$section->addText($data['desc'], $styleContentFont, $styleContentParagraph);
$section->addTextBreak(2);
}
$section->addPageBreak();
//New page
$section->addText('Non-Functional Requirements', $styleHeadingFont, $styleHeadingParagraph);
$section->addTextBreak(3);
while($data = $sql_nonfunc->fetch_array())
{
$section->addText($data['type'], $styleSubFont, $styleSubParagraph);
$section->addTextBreak();
$section->addText($data['desc'], $styleContentFont, $styleContentParagraph);
$section->addTextBreak(2);
}
// At least write the document to webspace:
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
$file = "SRS_".rand(1111, 9999)."docx";
if($objWriter->save($file))
return $file;
}
?>