Replies: 4 comments 3 replies
-
It's hard to see, but there is a leading space on the first column if you select all of that. |
Beta Was this translation helpful? Give feedback.
-
Hi John. Could you elaborate a little on what you have in mind? Which library method are you using in this case? Are you asking for all values and column names added to a worksheet to be trimmed? I'm not sure that should happen by default and would be considered a breaking change for some, although I'm strugging to think of a real use case for leading/trailing spaces. You could argue that it's the developer's job to ensure the data is in the right form, including trimming, before it's passed to the library. Perhaps it could be an option, but I'm loathe to add yet another argument to what are already very crowded method signatures in many cases. Maybe a global init setting might work better, given it would affect so many methods. Thoughts? |
Beta Was this translation helpful? Give feedback.
-
@Daemach
So I'm not sure how to replicate the issue you're seeing? |
Beta Was this translation helpful? Give feedback.
-
That is good foresight and apparently that wasn’t the problem after all.
I’ll keep looking, and great work as always.
…On Fri, Aug 4, 2023 at 8:39 AM Julian Halliwell ***@***.***> wrote:
@Daemach <https://github.com/Daemach> csvToQuery() apparently already
trims column names and values:
<cfscript>
spreadsheet = New spreadsheet.Spreadsheet()
// create a CSV string with columns and values that have leading+trailing spaces
csv = ' Name , Phone #NewLine()# Frumpo , 12345 '
queryFromCsv = spreadsheet.csvToQuery( csv: csv, firstRowIsHeader: true )
columns = QueryColumnList( queryFromCsv )
</cfscript>
<cfoutput>
<h2>Raw CSV</h2>
<pre>#csv#</pre>
<h2>Query Columns</h2>
<pre>#columns#</pre>
<h2>Query values</h2>
<cfloop list="#columns#" item="column">
<pre>#queryFromCsv[ column ]#</pre>
</cfloop>
</cfoutput>
[image: Screenshot 2023-08-04 at 16-21-09 https __test]
<https://user-images.githubusercontent.com/456718/258462169-d6311ae7-3ffc-4142-9205-4ea218608dc5.png>
And read() trims the column names (but not string values):
<cfscript>
spreadsheet = New spreadsheet.Spreadsheet()
//write a spreadsheet file with columns and values that have leading+trailing spaces
path = ExpandPath( "test.xlsx" )
spreadsheet.newChainable( "xlsx" )
.addRow( [ ' Name ', ' Phone ' ] )
.addRow( [ ' Frumpo ', ' 1234 ' ] )
.write( path, true )
queryFromXlsx = spreadsheet.read( src: path, format: "query", headerRow: 1 )
columns = QueryColumnList( queryFromXlsx )
</cfscript>
<cfoutput>
<h2>Query Columns</h2>
<pre>#columns#</pre>
<h2>Query values</h2>
<cfloop list="#columns#" item="column">
<pre>#queryFromXlsx[ column ]#</pre>
</cfloop>
</cfoutput>
[image: xlsx]
<https://user-images.githubusercontent.com/456718/258464985-8d9cec97-e8c3-4cca-948b-929242704f90.png>
[image: Screenshot 2023-08-04 at 16-31-56 https __test]
<https://user-images.githubusercontent.com/456718/258465025-393b3448-85c7-4831-a0d1-d55daaf964d8.png>
So I'm not sure how to replicate the issue you're seeing?
—
Reply to this email directly, view it on GitHub
<#329 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AC7Y5YPIJHD7IPZPMX6TGULXTUJUJANCNFSM6AAAAAA3B2ZVYM>
.
You are receiving this because you were mentioned.Message ID:
<cfsimplicity/spreadsheet-cfml/repo-discussions/329/comments/6640050@
github.com>
|
Beta Was this translation helpful? Give feedback.
-
@cfsimplicity I found my first CSV file today that looks like the one below. Can spreadsheet-cfml trim column names and values? I'll have to handle the non numerics, but auto-trimming would be lovely.
Beta Was this translation helpful? Give feedback.
All reactions