Google spreadsheet dates/times broken compared to Excel? - gwt

Apologies for yet another date/time related post. I haven't got my head around this yet, so any comments welcome. Executive summary: Excel can be used to work with small elapsed times (athletic event times, and so on), but Sheets can't, because you need to write a script to display small times, and the script screws something up so that Sheets no longer treats the cell as a time when the time is later manually changed.
The times I need are normally short, in the region of a couple of minutes, with seconds to 2 decimal places. I have to do arithmetic on these times (normally only comparisons to another time).
We currently store everything in Excel, which works fine. If you define a custom display format in a range, and then enter times as something like 2:43.02 (2 mins, 43.02s), then the cell still contains a time, and Excel can do arithmetic on those times.
I then upload the Excel spreadsheet, and open it in Sheets. There is no built-in formatting extension, as there is in Excel, so I have to use an extension function to display the time as 2:43.02, for example (see below; the function calls setNumberFormat). In the new Sheets version of the document, Excel times are still times, and comparison works, and everything looks right.
Here's the problem. Everything only works until you manually enter a new time into a Sheets cell. If I enter 2:41.05, for example, the cell no longer contains a time object, and all arithmetic is broken. So, I can't use Sheets to replace Excel. I have to keep everything in Excel and upload it occasionally, keeping the Sheets version as read-only.
There's some magic in Sheets which determines whether a cell contains a date or not. If I use a built-in time format, then Sheets knows it's a time, and can do arithmetic if the time is manually changed. If I change the time format using the function below (from here), then that magic is lost, and I can't manually change the time.
function EditFormat() {
var oldname = SpreadsheetApp.getActiveRange().getNumberFormat();
var name = Browser.inputBox("Current format (blank = no change):\r\n"+ oldname);
SpreadsheetApp.getActiveRange().setNumberFormat((name=="")?oldname:name);
}
Question: is setNumberFormat broken? Is there a better way to do all this? Can I do something else in the script which retains the cell's magic status as a time? Or do I have to go back to Excel?
Thanks.

This is due to a (sadly long-standing) Sheets bug whereby the parser fails in two respects:
The format 2:43.02 is not successfully coerced into a time value, but the format 0:02:43.02 (or 0:2:43.02) is.
Even so, the hundredths of seconds are ignored for directly entered values.
Both points apply for all values in the spreadsheet, however only point two applies for directly entered values. So a workaround is to enter via a formula:
=VALUE("0:2:43.02")
or you could have an input column that is formatted as plain text, and then have a display column that similarly converts to a time value via formula (and this display column would be custom formatted). Or, you could have a helper script that presents an input box for the active cell, where you enter the split time, and then creates a formula like above and populates it in the cell (the set number format could be built in to this script as well).
I wish these workarounds were unnecessary.

Related

MINIFS/MAXIFS formula breaks in LibreOffice Calc but works in Excel and Sheets?

I'm trying to convert a bunch of spreadsheets from Excel to LibreOffice Calc and I have one formula that works perfectly in Excel and I even tried Google Sheets but it gives a #NAME? error only in LibreOffice Calc. I think it's something to do with the " " or maybe missing $ but I've tried a bunch of troubleshooting with no success. I'm new to Calc so maybe I'm missing a formatting rule...
The formula is supposed to create a min/max date range for an alphanumeric code that could be anywhere inside a cell in the range. It's used to show when an action started and when it stopped. It works perfectly in Excel and Google Sheets but not with Calc.
=TEXT(MINIFS($master data.H:H,$master data.AE:AE,"*"&B3&"*"),"yyyy")&" - "&TEXT(MAXIFS($master data.H:H,$master data.AE:AE,"*"&B3&"*"),"yyyy")
The formula should return something like 2003 - 2004 but instead it returns 1899 - 1899 for everything.
This version of the formula works perfect in Google Sheets:
=TEXT(MINIFS('master data'!H:H,'master data'!AE:AE, "*"&B3&"*"),"yyyy")&" - "&TEXT(MAXIFS('master data'!H:H,'master data'!AE:AE, "*"&B3&"*"),"yyyy")
The problem is your sheet name is 'master data', which has a space in between. Different program quotes differently.
For Calc, you should use single quote after the $, like this:
$'master data'
So your formula should be something like this:
=TEXT(MINIFS($'master data'.H:H,$'master data'.AE:AE,"*"&B3&"*"),"yyyy")&" - "&TEXT(MAXIFS($'master data'.H:H,$'master data'.AE:AE,"*"&B3&"*"),"yyyy")
In the future, if you run into issues with formula, you should break down the long formula, and try to solve each issue as you encounter it. So for this case, I simply tried to see how Calc would reference another sheet by entering = then click on a cell (say A1) in "master data". The result was:
=$'master data'.A1

Convert spreadsheet to .csv on command line without evaluating formulas

I want to convert a spreadsheet (e.g. .xls or from LibreOffice Calc) to some text format, e.g. .csv, without evaluating formulas so the formulas are stored in the text file. I know that LibreOffice has an option "Save cell formula instead of calculated values" when saving as .csv and according to How to export spreadsheet to CSV without evaluating formulas Excel can do this too, but I'd like to do it on command line. I know that ssconvert from the Gnumeric package can convert on command line but as fa as I ca see there's no option to keep the formulas.
The bigger picture is that I want to write a script that takes two versions of an .ods file, converts them and shows the differences. When only one cell has really changed but many other cells depend on it, then I want to see only the real change.
I have used xls2csv under Cygwin. Just a Google search shows many implementations. I would start there.
http://search.cpan.org/~ken/xls2csv-1.07/script/xls2csv

Bulk change date to present date with ExifTool

I have a bunch of images with different create dates. I want to normalize them all to a given date (say today's date) using a batch file (Windows). Can ExifTool set dates? I only see documentation and examples for shifting dates. To shift the date to present, I would need to somehow read the date for each file, calculate the difference, and then shift. That would be ok, but I don't know how to read the create date into a variable using ExifTool.
One obstacle for me is that I don't speak Perl. I do Python, and there is pyexiv2. This allows to write the "date", but I can't see anywhere if that is just create date or all dates.
Edit
Here shows using, for example,
exiftool -AllDates='2010:08:08 15:35:33' -overwrite_original IMG_01.jpg
in Ubuntu linux, but I could not get that to work in Windows.
As a hack, I tried
exiftool -AllDates+=2015:03:02 IMG_8220.JPG
which set the dates to the time executed, probably because the shift was so completely crazy. But I'd like to have control, and, specifically be able to change YYYY:MM:DD without changing the time.
Consequently, help still appreciated.
I crossposted to the ExifTool forum, and ExifTool author Phil Harvey responded that you need to use double quotes. The single quotes from the linked blog post don't do it in Windows.
So, one would use
exiftool -AllDates="2010:08:08 15:35:33" IMG_01.jpg
I tested it and (of course) it worked.

Is there a way to detect when a field mark with 'can grow' has truncated the field data?

I do not normally work with crystal, but I have spent nearly 2 days looking for a way to do this.
The problem is that I have a number of lines of text that need to show on a report, but need to cut off after 8 lines and show a 'more' prompt to inform the user that they need to go look at the rest of the details online. This was originally handled by storing the data as individual lines already wrap to size and counting the lines with a formula and conditionally showing a separate 'more' field. They have since added the ability to use html to the text, but this made the current way of doing things wrap incorrectly and show the html mark up.
I wrote a database function to combine the text into a single field and use the HTML text interpretation to display it correctly on 7 other reports that do not limit the text length, and the max line count works great for limiting the text size, I just can't figure out how to show the 'more' prompt when needed.
Any suggestions would be greatly appreciated.
GrumpyGeek,
If your database function now combines the text into a single field does this mean the original way, with the separated lines, is still stored? If so, why not add another calculated field called 'line-count' that tallies the old line-based data?
So you'd still have your new combined HTML field and this new field that you could use to show the 'more' button when 'line-count > x'?
Alternatively, another option might work, but would be a bit touchy. That is to make the formula that shows the more button trigger when the field length exceeds x. The catch is that html mark-up isn't displayed, and heavy use of it would skew the amount of text required before you should show the 'more' button. Put another way, a field with very heavy use of mark-up ( and tags) might force the 'more' button earlier than it should. Unless you could somehow make either your 'line-count' calculated field exclude the mark-up OR make the length calculation do the same.
This would be possible if MSSQL or Crystal Reports could run regex to strip the mark-up.
If NONE of the above works, the only other thing I can suggest is to look into UDFs. Crystal allows you to load an external library that you write. These will read functions you write and show them in the function list inside Crystal. If you do this, then you could easily write a routine that strips the HTML and calculates when the more button should be shown.
Good luck with it.
Ideally, there would be a property of the DB field that would return its displayed line count. Unfortunately, there is no such property.
You could try counting the # of line ending characters (e.g. carriage return, line feed). If they are > 7 then show the hyperlink. In a HTML situation, you have to count ending elements (e.g. ). You could make use of a RegEx UFL to make it easier to identify the elements.
Probably the easiest route is to the DB to calculate the # of lines and return that as another field. Use this field to hide/show the hyperlink.

How to change PowerPoint chart data with .NET?

I have a PowerPoint template that contains one slide and on that slide is a chart. I'd like to be able to manipulate that chart's data using .NET.
So far I have code that...
unzips the Powerpoint file.
unzips the embedded excel file (ppt\embeddings\Microsoft_Office_Excel_Worksheet1.xlsx)
It successfully manipulates the data in the excel sheet and zips it back up.
Opens and manipulates ppt\charts\chart1.xml
Powerpoint is then zipped up and delivered to the user
The result of this is a PowerPoint file that shows a blank chart. But when I click on the chart and go to edit data it updates the data and shows the correct chart.
I believe my problem is with the chart1.xml that I am generating. I have compared my generated version with a version created by PowerPoint and they are almost identical. The only differences are in the values for <c:crossAx/> and <c:axId/>.
There are also some rounding differences in the data. But I do not feel like that would result in a blank chart.
Is there another file that I need to edit? Does anyone have any ideas as to what else I should try to get this working?
It's likely a combination the axID value and the rounding issues. The Axis ID, likely, is asking for an integer value and you may be supplying a single/double. So the cached data in chart1.xml doesn't know how to display.
Try your same manipulation that you've been doing, but instead of opening the result in PowerPoint, change the .pptx extention to .zip, unzip and then manually fix the rounding issues to match the original rounding. Then zip back up, change extension back to .pptx and open in PowerPoint. If this fixes the issue of display, you can confirm it is the rounding issue.
Alternatively, and along the same lines. Open your resulting PPTX in PowerPoint as you have been doing, and once you've right-clicked and rehydrated the chart, save as a different file name and compare that with your automated result.