How to add a line break somewhere between the &

2019-02-26 08:53发布

I am creating a spreadsheet in google sheets that will be used to track the inventory of a property room. I am using QR codes as labels that will be placed on the property and will correlate to the pertinent information on that particular piece of property. I am using the following code...

=image("https://chart.googleapis.com/chart?chs=200x200&cht=qr&chl=" & "Category"&A3 & 
"Incident"&B3 & "Officer"&C3 & "Location"&D3 & "Owner"&E3 & "Description/Condition"&
F3 & "Date/TimeCollected"&G3 & "From/To(Date/Time)"&H3 & "From/To(Date/Time)"&
I3 & "From/To(Date/Time)"&J3 & "PropertyRoomLocation(Date/Time/Who)"&K3 & "KeepUntil"&L3)

Each row will correlate to one piece of property, and there will be several columns for different pieces of information on each piece of property.

So far, everything works just fine, however there is a formatting issues I run into when the data is displayed after scanning the QR code. When I scan the QR code, the information is displayed side by side as so..

Information1Information2Information3Information4

This is problematic as there are no spaces, and I understand that for whatever reason, spaces break up the code and prevent the QR code working. I am looking to have the information displayed with each new piece of information on a separate line as so...

Information1
Information2
Information3
Information4

It appears that I need to figure out how to add a line break somewhere between the &'s, and I cannot seem to get it to work.

1条回答
霸刀☆藐视天下
2楼-- · 2019-02-26 09:35

To encode line breaks, you need to use percent encoding. The line break character is %0A.

Hence your URL would need to be:

=image("https://chart.googleapis.com/chart?chs=200x200&cht=qr&chl=" & "Category"&A3 & "%0AIncident"&B3 & "%0AOfficer"&C3 & "%0ALocation"&D3 & "%0AOwner"&E3 & "%0ADescription/Condition"&F3 & "%0ADate/TimeCollected"&G3 & "%0AFrom/To(Date/Time)"&H3 & "%0AFrom/To(Date/Time)"&I3 & "%0AFrom/To(Date/Time)"&J3 & "%0APropertyRoomLocation(Date/Time/Who)"&K3 & "%0AKeepUntil"&L3)

Note that manual percent encoding of URL isn't a good idea: if you have any illegal URL character in your data cells, this will break your QR code. The best would be to create a URL encode custom function to process your data cells.

Here's such a custom function (use Tools→Script editor… to enter this in your sheet):

/**
 * Converts a string to a properly encoded URI
 *
 * @param {string}  component  The component you want to encode
 * @return {string}            The encoded URI component.
 * @customfunction
 */
function urlencode ( component ) {
    if ( component && component.map ) {
    return component.map ( urlencode );
  }
  else {
    return encodeURIComponent ( component || "" ) ;
  }

}

Now, if you have the following data: enter image description here

And if you enter the formula:

=image("https://chart.googleapis.com/chart?chs=200x200&cht=qr&chl="
& urlencode(join(char(10),arrayformula($1:$1&":"&3:3))))

into a cell of your spreadsheet, you'll get the following QR code:

enter image description here

(Note that $1:$1 refers to the entire first row in absolute reference, and 3:3 refers to row 3 in relative reference). Reading the QR code should yield:

parameter:owner
value:Jean-René Bouvier
comments:JRB

Let us know if this solves your issue.

查看更多
登录 后发表回答