I'm trying to format numbers in an Excel file using PHP and opentbs.
Here's template code I'm working from:
[gross_pay_names;block=begin;sub1=departments][gross_pay_names.name]
[gross_pay_names_sub1;block=begin]
[gross_pay_names_sub1.val; ope=tbs:num]
[gross_pay_names_sub1;block=end]
[gross_pay_names;block=end]
The problem is in the third line:
[gross_pay_names_sub1.val; ope=tbs:num]
It always renders with an apostrophe in the beginning ('0.00). So I can't use it in other formulas in the file.
Ok, I found a solutions myself. In case anybody needs it in the future here's the template code I ended up using:
[gross_pay_names.name;block=tbs:row;sub1=departments] [gross_pay_names_sub1.val;block=tbs:cell;ope=tbs:num]
A component of a project I am working on is to import text in cells from Excel using PHPExcel as a quicker way to populate the MySQL database.
How can I achieve preserving the Rich Text formatting of the Cell Contents e.g. "The Quick Brown Fox".
I am guessing it would require parsing the content-format somehow into matching HTML tags? Is there a way to achieve this in PHPExcel?
Thanks!
It's mentioned in the documentation.
$objRichText = new PHPExcel_RichText();
$objRichText->createText('This invoice is ');
$objPayable = $objRichText->createTextRun('payable within thirty days after the end of the month');
$objPayable->getFont()->setBold(true);
$objPayable->getFont()->setItalic(true);
$objPayable->getFont()->setColor( new PHPExcel_Style_Color( PHPExcel_Style_Color::COLOR_DARKGREEN ) );
$objRichText->createText(', unless specified otherwise on the invoice.');
$objPHPExcel->getActiveSheet()->getCell('A18')->setValue($objRichText);
I found this in a .csv file (maybe former excel sheet) and want to know what "language" this is:
a:6:{i:0;a:2:{s:3:"day";s:6:"Montag";s:7:"opening";s:11:"9:30 - 7:00";}
i:1;a:2:{s:3:"day";s:8:"Dienstag";s:7:"opening";s:11:"9:30 - 7:00";}
i:2;a:2:{s:3:"day";s:8:"Mittwoch";s:7:"opening";s:11:"9:30 - 7:00";}
i:3;a:2:{s:3:" ...
As i have to work with this data in a PHP context, i would like to read about the official syntax first, better than guessing how this is done ;)
This is not a "language". This is serialized data created with php function serialize(). You can deserialize() it.
I am newer for php. I want make php page cache, query data from mysql and store data into json format.
I have many questions:
which type of file should I store? .json or .txt or .cache? for I also need use json decode return datas into page.
I want use cron tab, make many mysql queries and write into one json file. what write code should I choose? fopen, fwrite or file_get_contents or other command? (do not cover the data, but continue write. I will deleted the file and renewer it at the next cron time)
If a multi write into a json data (10 or more mysql query at the same time and write into a same json file, each json child format like {name: ".$row['name']."}), how to completed a top { and bottom } to make a standad json data format?
{ //how to add this one
{name: ".$row['name']."}
{name: ".$row['name']."}
// many name from 10 more mysql queries
} //and this one
Thanks.
It's json_encode()
json_encode() — Returns the JSON representation of a value
<?php
$arr = array ('a'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>5);
echo json_encode($arr);
?>
which type of file should I store
It doesn't matter. There is no fixed extension, but I would pick .json just to make it clear what the file is supposed to contain.
what write code should I choose?
Just use file_put_contents to put the JSON string (see next section) into a file.
each json child format like
You really do not want to use that method. It might work for a while, but becomes very complex when you need to handle things like quoting and special-character escapes. Instead of re-inventing the wheel, use PHP's built-in JSON functions for this.
Create the data-structure you want using PHP's strings, numbers, and arrays, and then rely on json_encode to turn it into a string.
The main thing to be careful of is that depending on how your php array() looks, you might get JSON [] versus {}.
As far as saving the file as .txt or .json won't make a difference.
I think the focal point of this all lies in the json_encode page. Here's the example from that page:
This code:
<?php
$arr = array ('a'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>5);
echo json_encode($arr);
?>
Outputs like this:
{"a":1,"b":2,"c":3,"d":4,"e":5}
3 . You can use fopen and fwrite to write to your file. The second argument to fopen is the mode, you want to use 'a' for append.
Don't write your own cache because anything you write in PHP will be slower than can be supported by native extensions (like APC or memcached or even MySQL itself!!).
Don't cache as JSON. JSON is not a particulary 'fast' to serialize. If you're doing caching you don't want to do any serialization at all. Just store it as it is.
MySQL does query caching for you. If performance is a problem first tune your MySQL queries and database schema. Caching is one of the absolute last optimization you want to do.
If you want an easy way to cache, make a MySQL table called 'cache' and use that. If you want quick (small) file access, use MySQL (seriously). If you want an even faster cache access use an in-memory cache like APC or memcached.
How can you make a Koch Snowflake Fractal using php gd so that it comes out like this...
Is it possible? Is there another resource I can use?
imageline, imagerotate, imagefill, and imagefilledpolygon are your friends. they're all in the php manual. as far as the math goes, you can add this to your references: http://www.fractaldesign.net/algor.htm
You can create an image and draw lines on it using imageline.
Another posibility is using SVG. Since SVG are basically XML documents, you can make an SVG image by simply echo'ing some XML.
echo '<line x1="'.$startx.'" y1="'.$starty.'" x2="300" y2="300" />';