custom cell format or mask (GPS coordinates) in phpExcel? - gps

I'm trying to figure out how to use a custom cell format or create an input mask so users can enter data (32° 12' 13.44", 32° 12' 13.4" or 32° 12' 13") and not allow other formats, this is to avoid mistakes and because the application that processes the information needs the symbols (°, ', ") to distinguish each bit of the GPS coordinate.
I read this and tried it:
#NumberFormat.php
const FORMAT_GPS = '##°##\'##.##\"';
Controller:
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('A1', '32° 12\' 13.44"')
->setCellValue('B1', '32° 12\' 13.4"')
->setCellValue('C1', '32° 12\' 13"');
$phpExcelObject->getActiveSheet()->getStyle('A1:C2')->getNumberFormat()->applyFromArray(
array(
'code' => \PHPExcel_Style_NumberFormat::FORMAT_GPS
)
);
Note: I don't think it's correct...
However although it does show the format when clicking 'Format cells' it doesn't do anything when values that don't match the format are entered by the user.
How can I achieve this? Is it possible?

In MS Excel, I can use a mask something like:
##0"°"00"'"00\"
Perhaps something like
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1', 'Masked')
->setCellValue('B1', 'Degrees')
->setCellValue('C1', 'Minutes')
->setCellValue('D1', 'Seconds')
->setCellValue('E1', 'Decimal');
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A2', 532128.8864)
->setCellValue('B2', '=FLOOR(A2/10000,SIGN(A2))')
->setCellValue('C2', '=MOD(FLOOR(ABS(A2)/100,1),100)')
->setCellValue('D2', '=MOD(ABS(A2),100)')
->setCellValue('E2', '=(ABS(B2)+C2/60+D2/3600)*SIGN(A2)')
->setCellValue('F2', 'Latitude');
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A3', -21625.3338)
->setCellValue('B3', '=FLOOR(A3/10000,SIGN(A3))')
->setCellValue('C3', '=MOD(FLOOR(ABS(A3)/100,1),100)')
->setCellValue('D3', '=MOD(ABS(A3),100)')
->setCellValue('E3', '=(ABS(B3)+C3/60+D3/3600)*SIGN(A3)')
->setCellValue('F3', 'Longitude');
$objPHPExcel->getActiveSheet()
->getStyle('A2:A3')
->getNumberFormat()
->setFormatCode('##0"°"00"\'"00\"');
(Tested while waiting in Manchester airport)

Related

Python write function saves dataframe.__repr__ output but truncated?

I have a dataframe output as a result of running some code, like so
df = pd.DataFrame({
"i": self.direct_hit_i,
"domain name": self.domain_list,
"j": self.direct_hit_j,
"domain name 2": self.domain_list2,
"domain name cleaned": self.clean_domain_list,
"domain name cleaned 2": self.clean_domain_list2
})
All I was really looking for was a way to save these data to whatever file e.g. txt, csv but in a way where the columns of data align with the header. I was using df.to_csv() with \t delimeter but due to the data have different lengths of string and numbers, the elements within each row never quite line up as a column with the corresponding header. So I resulted to using
with open('./filename.txt', 'w') as fo:
fo.write(df.__repr__())
But bear in mind the data in the dataframe are lists with really long length. So for small lengths it returns
which is exactly what I want. However, when I have very big lists it gives me
So as seen below the outputs are truncated. I would like it to not be truncated since I'll need to manually scroll down and verify things.
Try the syntax:
with open('./filename.txt', 'w') as fo:
fo.write(f'{df!r}')
Another way of doing this export to csv would be to use a too like Mito, which full disclosure I'm the author of. It should allow you to export ot CSV easier than the process here!

Is there a more efficient way to parse a fixed txt file in Access than using queries?

I have a few large fixed with text files that have multiple specification formats in them. I need to parse out the txt files based on a character with a set location in the file. That character can have a different position in the file.
I have written queries for each of the different specifications (95 of them) with the start position and length hard coded into the query using the mid() function with a WHERE() function to filter the [Record Identifier] from the specification. As you can see below the 2 specifications in the WHERE() function have different placements in the txt file.
\\\
SELECT Mid([AllData],1,5) AS PlanNumber, Mid([AllData],6,4) AS Spaces1, Mid([AllData],10,3) AS Filler1, Mid([AllData],13,11) AS SSN, Mid([AllData],24,1) AS AccountIdentifier, Mid([AllData],25,5) AS Filler2, Mid([AllData],30,2) AS RecordIdentifier, Mid([AllData],32,1) AS FieldType, Mid([AllData],33,4) AS Filler3, Mid([AllData],37,8) AS HireDate, Mid([AllData],45,8) AS ParticipationDate, Mid([AllData],53,8) AS VestinDate, Mid([AllData],61,8) AS DateOfBirth, Mid([AllData],77,1) AS Spaces2, Mid([AllData],78,1) AS Reserved1, Mid([AllData],79,1) AS Reserved2, Mid([AllData],80,1) AS Spaces3
FROM TBL_Company1
WHERE (((Mid([AllData],30,2))="02") AND ((Mid([AllData],32,1))="D"));
\\\
Or
\\\
SELECT Mid([AllData],1,5) AS PlanNumber, Mid([AllData],6,4) AS Spaces1, Mid([AllData],10,3) AS Filler1, Mid([AllData],13,11) AS SSN, Mid([AllData],24,1) AS AccountIdentifier, Mid([AllData],25,7) AS RecordIdentifier, Mid([AllData],32,22) AS StreetAddressForBank, Mid([AllData],54,20) AS CityForBank, Mid([AllData],74,2) AS StateForBank, Mid([AllData],76,5) AS ZipCodeForBank
FROM TBL_Company1
WHERE (((Mid([AllData],25,7))="49EFTAD"));
\\\
Is there a way to Parse out this without having to hard code every position and length into the code?
I was thinking of having a table with all of the specifications in it and have an import function look to the specification table and parse out the data accordingly to a new table or maybe something else.
What I have done is not very scalable and if the format changes a little I would have to go back to each query to change it.
Any Help is greatly appreciated
I think in your situation, I'd want to be able to generate the SQL statement dynamically, as you suggest.
I'd have a table something like:
Format#,Position,OutColName,FromPos,Length,WhereValue
1,1,"PlanNumber",1,5,
1,2,"Spaces1",6,4,
...
1,n,,30,2,"02"
1,n+1,,32,1"D"
and then some VBA to process it and build and execute the SQL string(s). The SELECT clause entries would be recognized by having a value in the OutColName field and WHERE clause entries by values in the the WhereValue column.
Of course this is only more "efficient" in the sense that it's a bit easier to code up new formats or fix/modify existing ones.

Convert a spool into text format

I want to send the spool generated by a Smart Form, by email as attachment in TXT format.
The issue is to get the spool in a TXT format, without technical stuff, just the characters in the form.
I have used the function module RSPO_RETURN_SPOOLJOB for getting it, but it returns a technical format like this:
//XHPLJIIID 0700 00000+00000+
IN01ES_CA930_DEMO_3 FIRST
OPINCH12 P 144 240 1728020160000010000100001
IN02MAIN
MT0100808400
CP11000000E
FCCOURIER 120 00144 SF001SF001110000144E
UL +0000000000000
ST0201614Dear Customer,
MT0214209000
ST0864060We would like to take this opportunity to confirm the flight
MT0100809360
ST0763253reservations listed below. Thank you for your custom.
...
I want something as follows, without the technical stuff:
Dear Customer,
We would like to take this opportunity to confirm the flight
reservations listed below. Thank you for your custom.
...
This is the code I have used :
PARAMETERS spoolnum type TSP01-RQIDENT.
DATA spool_contents type soli_tab.
CALL FUNCTION 'RSPO_RETURN_SPOOLJOB'
exporting
rqident = spoolnum
tables
buffer = spool_contents
exceptions
others = 1.
If the parameter DESIRED_TYPE is not passed or has the value 'OTF', and the spool is of type SAPscript/Smart Form, the function module returns the technical format you have experienced.
Instead, you should use the parameter DESIRED_TYPE = 'RAW' so that all the technical stuff is interpreted and the form is returned as text, the way you request, as follows :
CALL FUNCTION 'RSPO_RETURN_SPOOLJOB'
exporting
rqident = spoolnum
desired_type = 'RAW'
tables
buffer = spool_contents
exceptions
others = 1.

Pentaho cuts double values from Table Input

I have a Problem that I could not fix up to now. When I do a "Select" at a Table-Input the double values are not returned completely and are always cut. Here are some examples:
15.0420 => 15 // 12.6000 => 12,6 // 4.1176 => 4,1 // 0.1123 => 0,1 // 0.0012 => 0
I seems like, that minimum two numbers are shown and max one number after the comma. However it is very important to get the right figures.
I use pentaho 6.1, and mariaDB 5.5.49.
Thanks for every help.
Best regards,
Dave
Finally I adjusted the configuration of the Default Number Format. Under "Edit->Edit the kettle.properties file", I set the "KETTLE_DEFAULT_NUMBER_FORMAT" with the format '#.####'. Now it is working!

Inserting string which contain single quotes ' in SQL

I've seen so many solutions to this that I don't know which one to follow.
I thought that what I have would work but upon further testing I have discovered that this is not true.
I'm using VB to pick up MS Excel worksheets from a given file directory, extract the data, and insert into SQL data tables.
here's the part I need some help with:
If saRet(linex, 11) <> "" Then
IntDesc = (saRet(linex, 11).ToString.Replace("'", "''"))
Echo("Internal description: " & IntDesc)
Else
Echo("No internal description given")
IntDesc = ""
End If
After tampering around with some test insert statements in SQL server studio I thought that replacing ' with '' worked. Sadly, not.
Here's an example of a string which makes the insert fail:
Set-up and Config of New Button on BP and UDF's for Despatch Process
and after my string manipulation, here's the Insert statement(I've blanked out some data which my company probably doesn't want to share, it's insignificant anyway):
NSERT INTO <tablename> VALUES ('2013-12-10', '12', '2013', 'AAAA', 'AAAA', '10668', 'JBT', 'Project - Config & System Build', 'CSB', '2', 'Y', 'N', '0', 'Set-up and Config of New Button on BP and UDF's for Despatch Process', 'Set-up and Config of New Button on BP and UDF''s for Despatch Process', '0', 'NULL')
Very grateful for any help!
Thanks.
The best way is always using parameters. Those handle everything for you and you don't need to do any escaping.
If you can't use parameters, you have to do the encoding yourself, and that's very tricky. One way would be to use a format you can encode safely - for example, instead of inserting as a string literal, you might use binary encoding (eg. cast(0xAABBCCDD as varchar(max))). This is perfectly safe, since you can be sure that there's no invalid character that would break it. Of course, it also has its problems.
As for your example, replacing ' with '' works fine (although of course you'd have to watch out for other invalid characters, such as endlines). Your problem is that you didn't do the encoding on all the strings. In your sample, the last string has the proper encoding, the one before it does not. This also beautifully illustrates the pain of making sure you're encoding properly - and everything you miss means an error, or even a way to exploit the code and cause harm. For example, what if the description was ', ''0'', ''NULL''); delete from users --?