I export data from database with dynamical columns and rows so I use R1R1 / $excel->setCellValueByColumnAndRow($col, $row, $value);
Row 2 is my title including autofilter and line 1 on some columns i want a =subtotal().
I tried as =SUBTOTAL() and =TEILERGEBNIS() as well as C1R1 and Standard:
$excel->setCellValueByColumnAndRow(12, 1, "=SUBTOTAL(9;C(2)S:R(".$i.")S)")");
$excel->setCellValue("M1", "=TEILERGEBNIS(9;M3:M".$i.")");
Excel will ask to restore and will set "M1" to 0.
If i copy this value of an echo to M1 it does what it should an is what the formula is as i do it in Excel itself: =TEILERGEBNIS(9;M3:M2315)
There's a couple of things wrong here
Commas (,), not semi-colons (;) for function argument separators (unless you've explicitly set a different locale for the calculation engine)
PHPExcel's calculation engine doesn't accept Column/Row addresses (like R1C1), just cell A1-style addresses
English names for functions (unless you've explicitly set a different locale for the calculation engine)
Related
I've searched and tried lots of things but I can't find a solution.
I am storing some SNMP OIDs in a database, and displaying them in a table with datatables.
I want the OIDs to be displayed in the correct order so for example:
1.3.6.1.2.1.1
1.3.6.1.2.1.10
1.3.6.1.2.1.2
In correct order would be:
1.3.6.1.2.1.1
1.3.6.1.2.1.2
1.3.6.1.2.1.10
A SQL query with order by on the column storing the OID string would order them:
1.3.6.1.2.1.1
1.3.6.1.2.1.10
1.3.6.1.2.1.2
I'm using serverside processing with either PHP or preferably python flask. Currently I am building the table myself in flask and have written a function that orders them by converting the OIDs to tuples and sorting. This works but I would like to use datatables to get the pagination and responsiveness.
One thing to note is there isn't a limit on the length of the OID.
Any ideas would be much appreciated.
This is kind of a hack, but it might work. If each element in the OID has a max value < 100, then create a second column in the database, where each element is converted to a 2-digit 0-filled value:
real_oid sorting_oid
1.3.6.1.2.1.1 01.03.06.01.02.01.01
1.3.6.1.2.1.10 01.03.06.01.02.01.10
1.3.6.1.2.1.2 01.03.06.01.02.01.02
You could even eliminate the periods to save space, once you tested that is is all working.
First split the string on the period and typecast to int. Then use sorted and operator.itemgetter to sort by multiple attributes. Then re-join using a period. Something like the following:
original_oids = [...]
split_and_typecast_oids = [map(int, oid.split(".")) for oid in original_oids]
sorted_oids = sorted(split_and_typecast_oids, operator.itemgetter(1,2,3,4,5,6,7))
rejoined_oids = [".".join(map(str, oid)) for oid in sorted_oids]
I'm trying to add some tables to a document, which after lot of work, it's showing right. Generated with PHPWord. The issue is that whatever I add in the table,row or cell style, it doesn't modify the table.
I've already tried: $table->addRow(15), $table->addRow(array('height'=>15)) and as is shown in the code below.
Also, there is no documentation on how to add a cell with two lines of text, because below 'Sign' I have to add 'Name'.
//TABLE1
$table = $section->addTable(array('width'=>100, 'borderSize'=> 1, 'borderColor'=>'000000'));
$table->addRow(15,array('height'=>15));
$table->addCell(array('width'=>150))->addText('COMPANY', $smallBoldFont);
$table->addRow();
$table->addCell()->addText('');
$table->addRow();
$table->addCell()->addText('');
//TABLE1
$section->addTextBreak(2);
//TABLE2
$table2 = $section->addTable(array('borderSize'=> 1, 'borderColor'=>'000000'));
$table2->addRow(100,array('height'=>80));
$table2->addCell(150,array('width'=>800))->addText('Recibed', $smallFont8);
$table2->addRow();
$table2->addCell()->addText('Time:', $smallFont8);
$table2->addCell()->addText('Sign:', $smallFont8);
//TABLE2
Is there a reason why PHPWord ignores my format style to tables? Is there any other way of doing it better?
Desired output:
Actual output:
In documentation is all. Just to read it deeply. Here is section how to create tables, including creation of tables with multicolumn cells
I don't know if PHPWord has some pre-defined units for case if you miss to use them. But it seems you need to set units for width. But you should test units and numbers as you need.
Order to create multicolumn cell is gridSpan(). So line for creation of the first row of the second table (probably) should be:
$table2->addCell(150,array('width'=>800))->gridSpan(2) ->addText('Recibed', $smallFont8);
PHPWord uses twip as default unit. And all cells have to match its width.
The smallest cell is taken for entire column.
For convertion from twips to other units may be used EndMemo (Topography Conversion Online).
250 pixels are 3750 twips.
In an excel sheet where I previousely formatted the whole first colum as a date, I changed afterwards the format of the used cells to General (cells A1 to A11). So from cell A12, this first column still has the previous date format.
When I try to use the values of the first column (A1, A2, ..., A11) it identifies their format as a date, and gives a wrong result.
For example, this retruns a date format (d/mm/yyyy), which is not the case (see picture)
$sheet->getStyle('A3')->getNumberFormat()->getFormatCode();
Also the whole column has this format :
$sheet->getStyle('A')->getNumberFormat()->getFormatCode();
Is there a way to make sure the format of the cell itself is considered?
(when I indicated the format of this cells explicitely, the right format was used)
After some investigation, found that this problem occurs only for the .xlsx files (using reader PHPExcel_Reader_Excel2007) and not for the .xls files (reader PHPExcel_Reader_Excel5).
You can set the whole row/col format:
$sheet->getStyle('A')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
Because you have changed only the format of A1 to A11, the rest are still with the old format. So setting format of the Whole Column/Row will fix this problem
After some more invetigation found a possible cause in reader Excel2007.php.
There is a problem with the condition When setting the style (line 933):
if ($c["s"] && !$this->_readDataOnly) {
$cell->setXfIndex(isset($styles[intval($c["s"])]) ? intval($c["s"]) : 0);
}
In case of General cell format, $c["s"] is not defined, and the _xfIndex of the cell is not set (not passing the if statement). This gives (I didn't found why) a problem with the stored _xfIndex of the cell.
When removing the $c["s"] condition, the right style is set.
if (/*$c["s"] &&*/ !$this->_readDataOnly) {
$cell->setXfIndex(isset($styles[intval($c["s"])]) ? intval($c["s"]) : 0);
}
Hoping there are no hidden consequences.
I have a mySQL database with the following
e.g.
Microeconomics.
The ‘theory of the ï¬rm’
or:
Resource allocation modiï¬cations.
For some reason, the text that has been input (through CKEditor), has been changed so any instances of fi are in the database as 'ï¬'. I believe this is something to do with HTML entities. The text (I believe) was copy-pasted from a word document, which could be part of the problem.
How do I change (in PHP or mySQL) all instances of 'ï¬' into fi? When rendered as a PDF by TCPDF, it shows a ? (e.g. financial = ?nancial, significant = signi?cant)
Thanks in advance.
This statement will correct all the false instances for the column that contains the 'ï¬'
Update table Set
column = replace(column, 'ï¬', 'fi')
Background:
I have this "with rollup" query defined in MySQL:
SELECT
case TRIM(company)
when 'apple' THEN 'AAPL'
when 'microsoft' THEN 'MSFT'
else '__xx__'
END as company
,case TRIM(division)
when 'hardware' THEN Trim(division)
when 'software' THEN Trim(division)
else '__xx__'
END as division
,concat( '$' , format(sum(trydollar),0)) as dollars
FROM pivtest
GROUP BY
company, division with rollup
And it generates this output:
AAPL;hardware;$279,296
AAPL;software;$293,620
AAPL;__xx__;$572,916
MSFT;hardware;$306,045
MSFT;software;$308,097
MSFT;__xx__;$614,142
__xx__;__xx__;$1,187,058
If you have used "with rollup" queries in MySQL before, you can most likely infer the structure of my source table.
Question:
Given this raw output of MySQL, what is the easiest way to get a "tree" structure like the following?
AAPL
hardware;$279,296
software;$293,620
Total; $572,916
MSFT
hardware;$306,045
software;$308,097
Total;$614,142
Total
$1,187,058
Easiest is to do it in whatever client program you're using to receive and show the user MySQL's output -- definitely not easiest to implement presentation-layer functionality in the data layer!-) So tell us what language &c is in your client program and we may be able to help...
Edit: giving a simple Python client-side solution at the original asker's request.
With Python's DB API, results from a DB query can be most simply seen as a list of tuples. So here's a function to format those results as required:
def formout(results):
marker = dict(__xx__=' Total')
current_stock = None
for stock, kind, cash in results:
if stock != current_stock:
print marker.get(stock, stock).strip()
current_stock = stock
if kind in marker and stock in marker:
kind = ' '*8
print ' %s;%s' % (marker.get(kind, kind), cash)
marker is a dictionary to map the special marker '__xx__' into the desired string in the output (I'm left-padding it appropriately for the "intermediate" totals, so when I print the final "grand total", I .strip() those blanks off). I also use it to check for the special case in which both of the first two columns are the marker (because in that case the second column needs to be turned into spaces instead). Feel free to ask in comments for any further clarification of Python idioms and use that may be necessary!
Here's the output I see when I call this function with the supplied data (turned into a list of 7 tuples of 3 strings each):
AAPL
hardware;$279,296
software;$293,620
Total;$572,916
MSFT
hardware;$306,045
software;$308,097
Total;$614,142
Total
;$1,187,058
The space-alignment is not identical to that I see in the question (which is a little inconsistent in terms of how many spaces are supposed to be where) but I hope it's close enough to what you want to make it easy for you to adjust this to your exact needs (as you're having to translate Python into PHP anyway, the space-adjustment should hopefully be the least of it).