Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line breaks are not supported (Excel Mac 2011) #252

Closed
niallsmart opened this issue Oct 8, 2013 · 18 comments
Closed

Line breaks are not supported (Excel Mac 2011) #252

niallsmart opened this issue Oct 8, 2013 · 18 comments

Comments

@niallsmart
Copy link

@niallsmart niallsmart commented Oct 8, 2013

Axlsx 2.0.1 does not support line breaks in cells, as tested in Excel Mac 2011.

Test case is here:

https://gist.github.com/niallsmart/6878157

@kbaum
Copy link

@kbaum kbaum commented Oct 28, 2013

I am running into this issue as well.

@kbaum
Copy link

@kbaum kbaum commented Oct 28, 2013

@niallsmart I rolled back to the merge fix #127 and your test case still doesn't work. I am also on Mac 2011.. perhaps this never worked?

@noniq
Copy link
Collaborator

@noniq noniq commented Oct 28, 2013

You have to use shared strings to make multiline strings work correctly (don’t ask me why …). Just add the following line to your test case:

package.use_shared_strings = true

@niallsmart
Copy link
Author

@niallsmart niallsmart commented Oct 29, 2013

@noniq good to know, thanks.

@kbaum
Copy link

@kbaum kbaum commented Oct 29, 2013

@niallsmart - Maybe a silly question, but how did you figure that out? What are the best resources for understanding how to get microsoft excel to do what you want? Seems very challenging to say the least.

thx!

@noniq
Copy link
Collaborator

@noniq noniq commented Oct 29, 2013

Are you referring to the use of shared strings? I found that out by comparing an file created by Excel itself (linebreaks working) with the one written by Axlsx (linebreaks not working) – the only difference I noticed was that Excel’s file used shared strings.

I think it’s just a bug in Excel 2011 for Mac that it seems to not support linebreaks in files without shared strings. I guess all versions of Excel (maybe Open Office, too?) always create files with shared strings, so the bug only shows when opening files created with tools like Axlsx.

@kbaum
Copy link

@kbaum kbaum commented Oct 30, 2013

@noniq - How do you go about that comparison when axlsx generates a binary file? Also, what does "shared strings" refer to?

thx!

@niallsmart
Copy link
Author

@niallsmart niallsmart commented Oct 30, 2013

@kbaum well, I was not actually the person who figured that out :) Personally I have found StackOverflow and the discussions on GitHub to be useful for debugging problems. Shared strings is a reference to the package level setting referred to in an earlier comment on this issue.

@kbaum
Copy link

@kbaum kbaum commented Oct 30, 2013

Right.. i get that it's a setting.. but beyond that, what does it mean?

@niallsmart
Copy link
Author

@niallsmart niallsmart commented Oct 30, 2013

@kbaum it's a technique used to reduce file size by storing references to commonly used strings in a table, instead of repeating them inline. you can find more information here: http://msdn.microsoft.com/en-us/library/office/gg278314.aspx

@noniq
Copy link
Collaborator

@noniq noniq commented Oct 30, 2013

@kbaum xlsx files are in a format called Office Open XML (OOXML) – that means they are in fact just a ZIP file containing a bunch of XML files. You can change the extension from xlsx to zip to simply extract and view the contents.

For more info about OOXML see https://en.wikipedia.org/wiki/Office_Open_XML

@kbaum
Copy link

@kbaum kbaum commented Oct 30, 2013

@noniq - wow.. that is super helpful. Thanks for your help!

@noniq
Copy link
Collaborator

@noniq noniq commented Oct 30, 2013

@kbaum @niallsmart To round this up: Can you confirm that multiline strings in Excel 2011 Mac work correctly for both of you if the file is written with use_shared_strings = true?

@kbaum
Copy link

@kbaum kbaum commented Oct 30, 2013

@noniq - yes.. use_shared_strings = true did the trick!

@noniq
Copy link
Collaborator

@noniq noniq commented Oct 31, 2013

Summary: This appears to be a bug in Excel Mac 2011, use_shared_strings = true can be used as workaround.

@noniq noniq closed this as completed Oct 31, 2013
@futbolpal
Copy link

@futbolpal futbolpal commented Feb 3, 2016

did anyone find this created a very very wide column?

@NoSkillGuy
Copy link

@NoSkillGuy NoSkillGuy commented Jun 14, 2016

p = Axlsx::Package.new
p.use_shared_strings = true
p.workbook.add_worksheet(:name => "multiple_lines") do |sheet|
wrap = p.workbook.styles.add_style alignment: {wrap_text: true}
sheet.add_row arr, style: wrap
end

Adding this style will add new line to cell. I tried it in Mac OSX 10.11.4

@benedikt-voigt
Copy link

@benedikt-voigt benedikt-voigt commented Aug 8, 2017

In case you use join to concatenate lines, take double quotes (somehow single quotes don't work):
['Foo', 'Bar'].join("\n")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants