I'm creating a xlsx file from a html table like this:
$tmpfile = tempnam( sys_get_temp_dir(), 'html' );
file_put_contents($tmpfile, utf8_decode( $tablahtml2paraexcel ));
$excelHTMLReader = \PHPExcel_IOFactory::createReader('HTML');
$excelHTMLReader->loadIntoExisting($tmpfile, $phpExcelObjectTemp2);
$objWorkSheetBase = $phpExcelObjectTemp2->getSheet();
$objWorkSheetBase->setTitle('Empresas Mayor Contratacion');
$phpExcelObject->addSheet($objWorkSheetBase);
But I need to add style and formating to the cells created on the xlsx, like bold, center, vertical alignment, etc. I know how to do it when you build the entire xlsx (2007) cell by cell:
$styleBold = array('font' => array('bold' => true));
$phpExcelObject->getActiveSheet()->getStyle('B2')->applyFromArray($styleBold);
but don't know how to do it from a html table.
You do it in exactly the same way as when you build the entire xlsx (2007) cell by cell... those style methods work on any PHPExcel object, and it doesn't matter whether that object was created by loading an xlsx file, a csv file, an html file, or by creating a new PHPExcel object using new. Once the PHPExcel object has been created, then it's simply a PHPExcel object, with all the methods available to a PHPExcel object.
Related
I have a table in Sql that has 2 columns containing header and address of images that related to that header like below:
Header address
194003 ~/viewerImages/1903-01-1-5-0-6-00143.jpg
194003 ~/viewerImages/1903-01-1-5-0-6-00161.jpg
194003 ~/viewerImages/1903-01-1-5-0-6-00190.jpg
194012 ~/viewerImages/1903-01-1-5-0-6-00143.jpg
194012 ~/viewerImages/1903-01-1-5-0-7-00141.jpg
194012 ~/viewerImages/1903-01-1-5-0-7-00160.jpg
194015 ~/viewerImages/1903-01-1-5-0-7-00180.jpg
194015 ~/viewerImages/1903-01-1-5-0-8-00159.jpg
194015 ~/viewerImages/1903-01-1-5-0-8-00184.jpg
I want to load these images dynamically in fastreport for each header.
what should I do?
One solution is to create an objet with some properties that are the images to load (image1, image2, image3). You also add more properties with the data that you want to print in the report.
Then, you can load the information in the object dinamically and after send the object to the report, so Fast Reports will print the information you are loading in the object. In this way you can do wharever you want dinamically.
For image properties, you can use Image or byte[] type.
To create the report:
var report = new Report();
report.Load(Constants.Paths.ReportFolder + "Return.frx");
report.RegisterData(myObject, "Name");
report.Design(); // if you want to open the designer before to print
report.Show();
Note: The object to register must be a collection of objects. In this case myObject would be a List. If you want to register a single object, you can do it in this way:
report.RegisterData(new List{ myObject }), "Name");
In the designer you can access all the properties.
i am trying to load an html snippet variable into a spreadsheet.I have differnet sections which may have different dynamic html content. So i cant just convert manually.
$dynamic_code_snippet = '<ul><li>item one</li><li>item two</li></ul>';
At the moment i am trying this but get errors:
if(!empty($dynamic_code_snippet)){
$excelHTMLReader = PHPExcel_IOFactory::createReader('HTML');
$snippet = $excelHTMLReader->load($dynamic_code_snippet);
$snippetWriter = PHPExcel_IOFactory::createWriter($snippet,'Excel2007');
ob_start();
$snippetWriter->save('php://output');
$code = ob_get_clean();
$table->getActiveSheet()->setCellValue('A1, $code);
}
I get an error:
Fatal error: Uncaught PHPExcel_Reader_Exception: Could not open in PHPExcel\Reader\Abstract.php on line 196
Do you think its because its a snippet not a full page html document(no <html><head><body> tags)?
Can it be done? or do i have to rethink?
PHPExcel does provide a helper wizard that can be used to convert basic html markup to Riche Text Objects that can be set as a cell value:
$wizard = new PHPExcel_Helper_HTML;
$richText = $wizard->toRichTextObject($html);
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1', $richText);
However, only some markup tags are actively supported, and ordered/unordered lists aren't included.
If you want to take a look at it, and see how the code actually works, possibly modify it to work with lists, then it's the HTML.php file in /Classes/PHPExcel/Helper.
i'm using PDFizer library for .NET from here - PDFizer
and i need help... how i can convert all html document(including pictures stored in it) to PDF with this library? Now i can only generate pdf without images...
After some testing, this is what you need to do:
Create a Folder in which you will have all of your Images.
If you already have an instance of Pdfizer.HtmlToPdfConverter change the ImagePath Attribute to point to the folder where your images reside.
Include the <img> tags in your html code.
Make sure the images are in the folder.
Note: I tried adding Png files and got a conversion error. Here is an example I took from the site you provided, plus my modifications:
System.Text.StringBuilder sbHtml = new System.Text.StringBuilder();
sbHtml.Append("<html>");
sbHtml.Append("<body>");
sbHtml.Append("<font size='14'>My Document Title Line</font>");
sbHtml.Append("<img src='trollface.jpg' />");
sbHtml.Append("<br />");
sbHtml.Append("This is my document text");
sbHtml.Append("</body>");
sbHtml.Append("</html>");
//create file stream to PDF file to write to
using (System.IO.Stream stream = new System.IO.FileStream
(sPathToWritePdfTo, System.IO.FileMode.OpenOrCreate))
{
// create new instance of Pdfizer
Pdfizer.HtmlToPdfConverter htmlToPdf = new Pdfizer.HtmlToPdfConverter();
// open stream to write Pdf to to
htmlToPdf.Open(stream);
htmlToPdf.ImagePath = Server.MapPath(ResolveUrl("~/Images"));
// write the HTML to the component
htmlToPdf.Run(sbHtml.ToString());
// close the write operation and complete the PDF file
htmlToPdf.Close();
}
}
Good luck!
XElement xml = new XElement("contacts",
from c in db.Categories
orderby c.CategoryID
select new XElement("contact",
new XAttribute("contactId", c.CategoryID),
new XElement("firstName", c.CategoryName),
new XElement("lastName", c.Description))
);
// Saving to a file, you can also save to streams
xml.Save(#"C:\contacts.xml");
<dxm:ASPxMenu ID="ASPxMenu1" runat="server">
</dxm:ASPxMenu>
Using the above syntax i can save table value in XML format.But i can not bind this value to AspxMenubellow syntax show error.
ASPxMenu1.DataSource = xml;
ASPxMenu1.DataBind();
I try to save datavalue in xml format in specific location ,Then want to bind AspxMenu with this file value value.
After run the code C drive contain file named contacts.xml . I want to bind menu by this file.**Help me to bind.**HOw to bind AspxMenu by .xml file value
We have explained how to bind an ASPxMenu to an XMLDataSource in the following video:
http://tv.devexpress.com/#ASPxMenuBindXMLDataSource.movie
I hope, it will be helpful to you. In short, you should not only set the ASPxMenu's DataSourceID property, but also map item's Text, Image, Url, Name properties to the corresponding attributes in an xml node. This can be done by setting the ASPxMenu.TextField, ASPxMenu.ImageUrlField, ASPxMenu.NavigateUrlField and ASPxMenu.NameField properties. You can also read about these properties in our documentation available at:
http://documentation.devexpress.com
I am looking for a solution or recommendation to a problem I am having. I have a bunch of ASPX pages that will be localized and have a bunch of text that needs to be supported in 6 languages.
The people doing the translation will not have access to Visual Studio and the likely easiest tool is Excel. If we use Excel or even export to CSV, we need to be able to import to move to .resx files. So, what is the best method for this?
I am aware of this question, Convert a Visual Studio resource file to a text file? already and the use of Resx Editor but an easier solution would be preferred.
I'm not sure how comprehensive an answer you're looking for, but if you're really just using [string, string] pairs for your localization, and you're just looking for a quick way to load resource (.resx) files with the results of your translations, then the following will work as a fairly quick, low-tech solution.
The thing to remember is that .resx files are just XML documents, so it should be possible to manually load your data into the resource from an external piece of code. The following example worked for me in VS2005 and VS2008:
namespace SampleResourceImport
{
class Program
{
static void Main(string[] args)
{
XmlDocument doc = new XmlDocument();
string filePath = #"[file path to your resx file]";
doc.Load(filePath);
XmlElement root = doc.DocumentElement;
XmlElement datum = null;
XmlElement value = null;
XmlAttribute datumName = null;
XmlAttribute datumSpace = doc.CreateAttribute("xml:space");
datumSpace.Value = "preserve";
// The following mocks the actual retrieval of your localized text
// from a CSV or ?? document...
// CSV parsers are common enough that it shouldn't be too difficult
// to find one if that's the direction you go.
Dictionary<string, string> d = new Dictionary<string, string>();
d.Add("Label1", "First Name");
d.Add("Label2", "Last Name");
d.Add("Label3", "Date of Birth");
foreach (KeyValuePair<string, string> pair in d)
{
datum = doc.CreateElement("data");
datumName = doc.CreateAttribute("name");
datumName.Value = pair.Key;
value = doc.CreateElement("value");
value.InnerText = pair.Value;
datum.Attributes.Append(datumName);
datum.Attributes.Append(datumSpace);
datum.AppendChild(value);
root.AppendChild(datum);
}
doc.Save(filePath);
}
}
}
Obviously, the preceding method won't generate the code-behind for your resource, however opening the resource file in Visual Studio and toggling the accessibility modifier for the resource will (re)generate the static properties for you.
If you're looking for a completely XML-based solution (vs. CSV or Excel interop), you could also instruct your translators to store their translated content in Excel, saved as XML, then use XPath to retrieve your localization info. The only caveat being the file sizes tend to become pretty bloated.
Best of luck.
I ran into similar problem and realized that the simplest way to create a .resx file from excel file is using a concatenate function of excel to generate "<"data">".."<"/data">" node for the .resx file and then manually copying the generated rows to the .resx file in any text editor. So lets say that you have "Name" in column A of an excel document and "value" in Column B of the excel document. Using following formula in Column C
=CONCATENATE("<data name=","""",A14,""" xml:space=""preserve"">","<value>", B14, "</value>", "</data>")
you will get the data node for resource. You can then copy this formula to all the rows and then copy the contents of Column C in your .resx file.
If it's in csv here's a quick Ruby script to generate the data elements.
require 'csv'
require 'builder'
file = ARGV[0]
builder = Builder::XmlMarkup.new(:indent => 2)
CSV.foreach(file) do |row|
builder.data(:name => row[0], "xml:space" => :preserve) {|d| d.value(row[1]) }
end
File.open(file + ".xml", 'w') { |f| f.write(builder.target!) }