I want to export(force download) HTML(with CSS) to EXCEL sheet, for now I am using the PHPExcel library to perform this, it generate the excel file but remove the CSS (using inline with html tags), can anyone guide me, that how to keep CSS in excel sheet.
I am using this code, But I also want to keep the css and force to download
//html
$html = "<table>
<thead> <tr> <td colspan='2'> <h1> Main Heading </h1> <td> </tr> </thead>
<tbody>
<tr>
<th style='background:#ccc; color:red; font-size:15px'> Name <th>
<th style='background:#ccc; color:red; font-size:15px'> Class <th>
</tr>
<tr>
<td style='background:#fff; color:green; font-size:13px'> Jhon <th>
<td style='background:#fff; color:gree; font-size:13px'> 9th <th>
</tr>
</tbody>
</table>";
// Put the html into a temporary file
$tmpfile = time().'.html';
file_put_contents($tmpfile, $html);
// Read the contents of the file into PHPExcel Reader class
$reader = new PHPExcel_Reader_HTML;
$content = $reader->load($tmpfile);
// Pass to writer and output as needed
$objWriter = PHPExcel_IOFactory::createWriter($content, 'Excel2007');
$objWriter->save('excelfile.xlsx');
// Delete temporary file
unlink($tmpfile);
You can't read styles from HTML markup at the moment, unless you rewrite PHPExcel's HTML Reader to handle styles; it simply isn't supported yet. If you're building the spreadsheet from HTML, perhaps you should reconsider building it directly from a new PHPExcel object, which gives you access to all the features of PHPExcel.
To send to the browser, send to php://output with the appropriate headings, as shown in Examples/01simple-download-xlsx.php, and described in the section of the developer documentation entitled Redirect output to a client’s web browser
Related
I have requirement,where i need to send file content as mail body.can we dot through unix scripting.
Thanks in Advance
With the data create a html file. And then send that file in email as content.
use an expression to create your file data like this -
v_data= ' <tr>
<td>'||company ||'</td>
<td>'|| contact_person|| '</td>
<td>'|| country ||'</td>
</tr>'
Use an aggregator to concat all these data into one single row. group by none.
Then use another expression transformation.
create a ports like this -
v_head ='
<head></head>
<body>
<b>pls find below data.</b>
<table>
<tr>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>'
v_body = Aggregated_v_data
v_tail='</table></body>'
v_output = v_head||v_body ||v_tail
Then use this output and connect to a flat file target.
Then send this flat file sing mailx command/any mail client.
Output should look like this.
html file should looks like this
<head></head>
<body>
pls find below data.
<br> </br>
<table>
<tr>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr>
<td>Alfreds </td>
<td>Maria </td>
<td>Germany</td>
</tr>
</table>
</body>
My filter for the column is working, what I want to do now is make a default filter, that will applied on table creation.
<table id="testTable"
data-side-pagination="server">
<thead>
<tr>
<th class="question" data-field="UserFullName" data-sortable="false" data-filter-control="select">Name: </th>
<th class="question" data-field="UserJobTitle" data-sortable="false" data-filter-control="select" data-filter-data="var:userJobTitles">JobTitle: </th>
</tr>
</thead>
<script>
var userJobTitles = {
Admin: 'Admin',
IT: 'IT',
General : 'General',
Security : 'Security',
CEO : 'CEO',
};
</script>
In this example, I want to make IT Jobtitle a default job title.
This seems to be close to the solution bootstrap-table / How to add filter-control in table configuration , the issue is that i dont want to do it on the javascript side.
I think this feature is available out of the box in Bootstrap Table. Please see: filterDefault column option documentation
There is no need to write JavaScript for that, you could just use data-filter-default attribute on the <th> element corresponding to the column which you want to filter. So in your case it would be:
<th class="question"
data-field="UserJobTitle"
data-sortable="false"
data-filter-control="select"
data-filter-data="var:userJobTitles"
data-filter-default="IT">JobTitle: </th>
Important: It is necessary to use the "key" of your data-filter-data (see: filterData column option documentation).
Hopefully this helps :).
I am trying to generate pdf using TCPDF I have to parse dynamic data in pdf html table working fine.
App::import('Vendor', 'tcpdf');
$tcpdf = new TCPDF();
//$tcpdf->SetHeaderData($header_logo, $header_logo_width, $header_title,
PDF_HEADER_STRING);
$textfont = 'freesans';
$tcpdf->SetFooterMargin(PDF_MARGIN_FOOTER);
$tcpdf->AddPage();
$tcpdf->SetFont('dejavusans', '', 10, '', true);
$test = '
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td style="height:20px"></td>
</tr>
<tr>
<td style="text-align:center;">Test Report</td>
</tr>
<tr>
<td height="1"> </td>
</tr>
</table>
';
$test.="--- Dynamic Data----";
$html = <<<EOF
$test
EOF;
$filename="Test.pdf";
$tcpdf->writeHTML($html, true, false, true, false, '');
$tcpdf->lastPage();
//ob_end_clean();
$tcpdf->Output($filename, 'D');
The above code is working good, But When I parse CKEditor content along with dynamic content pdf design was collapse. There is one cell having CKEditor data (any data contents with html) When I was trying to generate pdf the Pdf design was collapse.
Is there any way to generate good format to generate pdf.
try to use MDFP which is a php class who generate pdf et see this video :
https://www.youtube.com/watch?v=fPbW7JhIZOQ
I have 2 objects results and headers being headers generated from _.keys(result[0])
r{
data:{
headers:['head1','head2']
result:[
{head1:'content1',head2:'content2'}
{head1:'content3',head2:'content4'}
{head1:'content5',head2:'content6'}
]
}
I have to create a table dinamically so I create this:
<table class="ui celled table segment">
<thead>
<tr>
{{#headers}}
<th>{{.}}</th>
{{/headers}}
</tr></thead>
<tbody>
{{#result:i}}
<tr>
{{#headers:h}}
<td>{{????}}</td> <-- Here is where I fail to know what to put into
{{/headers}}
</tr>
{{/result}}
</tbody>
</table>
Can someone help me to fill in the blanks. So I can create a table that display the contents
If I remove the {{#headers}} part and I already know the elements <td>{{.head1}}</td> work perfectly the problem is that I'am generating different objects on the fly.
{{#result:i}}
<tr>
{{#headers:h}}
<td>{{result[i][this]}}</td>
{{/headers}}
</tr>
{{/result}}
The reason this works is that the <td> is repeated for each item in the headers array, because it's inside a headers section - so far, so obvious. Because of that, we can use this to refer to the current header (head1, head2 etc). The trick is to get a reference to the current row - and because you've already created the i index reference, we can do that easily with result[i]. Hence result[i][this].
Here's a demo fiddle: http://jsfiddle.net/rich_harris/dkQ5Z/
I am creating a pdf and need to put a horizontal line in the page. Can anyone tell how to do that?
I have a xml file which has my html tag(<table>....</table>). And the whole content of xml file is parsed to a string which is used to create the pdf. Now some tags are not supported. One of them is <hr>. So is there any other tag which I can use in the xml file so that this will draw a
line when the pdf is created using xml data.
Below is an example of xml xontent
<table>
<tr>
<td>
<span>
This is working properly.
</span>
</td>
<tr>
</table>
<table>
<tr>
<td>
<span>
<hr>
This is not working properly.
</span>
</td>
<tr>
</table>
Please let me know if any more information is needed.
Thanks in advance.
The following creates a full width black line a few pixels thick, I'm using HTMLWorker.Parse:
<table>
<tr>
<td>
<span>
This is working properly.
</span>
</td>
<tr>
</table>
<table>
<tr>
<td>
<span>
<table border="1" cellpadding="0" cellspacing="0"><tr><td> </td></tr></table>
This is working properly now too!
</span>
</td>
<tr>
</table>
You can draw lines from begining postion (moveto), LineTo and then stroke (commit the line):
...
PdfContentByte cb = writer.DirectContent;
....
cb.MoveTo(doc.PageSize.Width / 2, doc.PageSize.Height / 2);
cb.LineTo(doc.PageSize.Width / 2, doc.PageSize.Height);
cb.Stroke();
...
I hope this helps you out
PdfPTable table = new PdfPTable(1); //Create a new table with one column
PdfPCell cellLeft = new PdfPCell(); //Create an empty cell
StyleSheet style = new StyleSheet(); //Declare a stylesheet
style.LoadTagStyle("h1", "border-bottom", "red"); //Create styles for your html tags which you think will be there in PDFText
List<IElement> objects = HTMLWorker.ParseToList(new StringReader(PDFText),style); //This transforms your HTML to a list of PDF compatible objects
for (int k = 0; k < objects.Count; ++k)
{
cellLeft.AddElement((IElement)objects[k]); //Add these objects to cell one by one
}
table.AddCell(cellLeft);