Can Spreadsheet::WriteExcel change the format of a cell without modifying its contents? - perl

In my Perl script I use the Spreadsheet::WriteExcel module to create an Excel file. The file contains a table, the size of which is dynamic - i.e., I don't know how many rows it will have until the table is already created. I would like the last row of the table to have a slightly different format (e.g., its bottom border to be "==="). Unfortunately, I cannot apply this (different) format at the time when the row is being created, since at that time I don't know yet that it will be the last row.
So, my question is: can I change the format of an already existing cell without changing its contents? If I pass undef as cell value to the $worksheet->write() method it just overwrites the contents of the cell with a blank cell.

The direct answer to your question is that you cannot modify the format of an already written cell in Spreadsheet::WriteExcel. This is a planned feature for Excel::Writer::XLSX but it isn't in place yet.
So you will need to workaround it in some way such as buffering the table data until you are ready to write it or buffering a row at a time and only writing it when you have a new row.
Or you could turn on compatiblilty_mode() and overwrite the last row with new formatted data. Note, this approach isn't recommended without compatibility_mode() since Excel will complain about duplicate and or missing data in the file.
Alternatively, setting the row format, as pointed out by #bvr, might work for you.

Unless your data is too big for memory, you can put your table data in an array first, then loop over the array to output. You'll have access to any element in the array to begin with, so you'll know what the last row will be and what kinds of data will be in it.

You can set the format to any row with set_row method without changing the data.

Related

How to prevent or make Data Interpreter to take only the first row in your CSV file to take as headers..?

I connected a new data source, a CSV file, in tableau, and the headers are displayed as F1, F2, and F3, so I did some googling. I found that I can use Data Interpreter to fix the issue, but after clicking it, it takes both the first and second rows combined as headers. Still, I only want the first row to be headers.. how do I make sure that only the first row is treated as headers instead of the first and second row combined.
I am attaching the screenshots for reference.
before using the data interpreter
after using the data interpreter

Relative Date Item in Power Pivot GETPIVOT DATA excel function

I am using a GETPIVOTDATA function in Excel to source data from a pivot table generated by a Power BI query (everything was originally only in excel, the file got too large, so i stored the main tables in PBI but kept the reports in excel for mgmt's sake).
=GETPIVOTDATA("[Measures].["&$A$100&"]",'PIVOT Table_test'!$A$126,"[Master].[field1]","[Master].[field1].&["&C$26&"]","[Master].[AsofDate]","[Master].[AsofDate].&[2022-04-30T00:00:00]")
However, I want to make the GETPIVOTDATA function as dynamic as possible to prevent having too many hardcoded fields/items for each table that fields the charts we look at. However, when i reference the pivot table, the '[Asof]' field populates the static item as "...&[2022-04-30T00:00:00]")...
I have been trying to change that to reference a header row that contains a Short Date value (4/30/2022) like &["&$B&1"&"]")... but i keep getting #ref errors, every other field accepts the "&&" method, and when i leave the hardcoded timestamp in the formula, it populates.
So it has to be that reference but i do not understand what I am doing wrong. I have also tried changing the format of both the header row in Excel and the field within PBI but to no success.
Found the answer on another site. The solution in the item brackets is to write the following:
["&TEXT($A22,"yyyy-mm-dd""T00:00:00""")&"]

How to make a cell Blank when no data is being delivered to it

I have made a sheet to track equipment for the company I work for. I have used a script to populate last edited date to a column when a specific column is populated with data. My issue is that once I remove the data from column "A", the date stays in column "B". Is there some sort of formula or script I can use to make the column blank again once it is not being fed data.
I'm using google sheets.
Thank you.
Kind regards.

Iterating all rows and changing a specific value ends up in a disappearing table

I have following problem: I have a small application running where i have implementes a language switching function. Therefore i need to change the datetime columns in footable for the right date format.
My idea was to iterate through all rows, get the date value, recalculate it in the right format and write it back to the table. But This approach is not working properly, when i try it, you can see the very first row changing, and then the whole table disappears. I have attached some screen shots and the relevant code to explain the problem...
My Code (for iterating the rows and changing the value):
var ft = FooTable.get("#spiele_data");
$.each(ft.rows.all, function(i, row){
v=row.val();
var m = moment(v.sp_timestamp, 'L LT');
v.sp_timestamp=m.format('L LT');
row.val(v);
});
This is what happens:
Table is loaded and displayes properly
After changing the language => see the first line
Immediatley after that the table is gone
What am i doing wrong or is there a better possibility to change specific columns in all rows?
Best regards
Christian
+EDIT: One more thing: the $.each-loop is iterated completely. I've tested that by writing the index to the console.
$('table').trigger('footable_redraw');
You need to call redraw to see footable again

ExcelWriter data column that is too big for a single cell

i have an ExcelWriter xlsx template that is populated via a datatable. Everything works perfectly but one column in the datatable is too large for the cell. The column is actually varchar(max) populated from text box area in a web application so the column can have multiple sentences in it. I tried to setup the xlsx template to do word wrap - and that works (kinda), but the text is still only in one cell. Is there a way to split or wrap the column across multiple cells vertically?
Text wrap is Excel's way of dealing with this issue. The other options are to alter your data before passing it to Excel Template so that your cell value is actually multiple rows in your data source.
If neither of these options are possible, A less desirable way might be to do some formula trickery where you store your large cell value in one cell and break it up into other cells with formulas such as LEFT MID or RIGHT
See http://www.excel-easy.com/functions/text-functions.html for some examples