-
Notifications
You must be signed in to change notification settings - Fork 697
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
Multiline text formatting #134
Comments
Hi @Priyanka §18.4.4 text runs If you want to have a go at this, fork the repo and have a look at lib/axlsx/workbook/worksheet/cell.rb |
I might need this feature in the near future and from a quick glance I gather the xml needed to achieve this is straight-forward. I wonder, though, what the API in axlsx should look like. Should axlsx parse a string with \b and \strike as shown above. Or HTML-like tags, like prawn does? Or would you prefer a more object-oriented approach? Maybe something like this pseudo-code: text = Axlsx::Text.new
text.append "This is "
text.append "bold", :style => :bold
sheet.add_row [text] |
I think that as a user of the API, I would prefer to do the least amount of work. Can you start with an object oriented approach that follows the specification, and then we can work out some kind of macro language for driving that? The basic model is:
We need to implement r(Rich Text Run) of which a cell can have many. That is serialized directly to the worksheet when shared_string is off inside of an elelement, and serialized into a element inside of the shared strings table. I image something like this, but the real work will happen in the RichTextRun object, parsing out the options to create a rPr object, a text object and manage the serialization of those parts, and Cell will need a fairly large re-write to handle existing 'inline styles' and proper serialization. #
class Axlsx::RichText
def initialize(text, options={})
@runs = SimpleTypedList.new(RichTextRun)
add_run(text, options)
yield self if block_given?
end
attr_reader :runs
def add_run(text, options={})
@runs << RichTextRun.new(text, options)
end
def to_xml_string(str='', tag='si')
str << "<#{tag}>"
runs.each{ |run| run.to_xml_string(str) }
str << "</#{tag}>"
end
end That should give us usage like this text_run = Axlsx::RichText.new('this is') do |rich_text|
rich_text.add_run('bold', :b => true)
rich_text.add_run(', but this is ')
rich_text.add_run('underlined and red.', :u => :double, :color => 'FF0000')
rich_text.add_run('in the end - this is just naked text')
end
sheet.add_row [text_run, 'simple inline string'] One caveat is that we need to maintain backwards compatibility for Cell and the inline style attributes so when someone sets. rows.first.cells.first.b = true We need to be sure to create a new run for all of the text or update all of the runs in that cell. Number of other small things that come to mind, like what do we return for 'value' when the consumer has created this kind of rich text, but those details will most likely sort themselves out over time. |
I am also in need of this unfortunately. Has anyone made any progress on this? thx! |
not a stitch, as far as I know @kbaum |
We are currently manually generating the excel with erb but if we change over to axlsx, I may take a stab at it. Thx! Sent from my iPhone On Aug 29, 2013, at 9:47 AM, "Randy Morgan (@morgan_randy)" notifications@github.com wrote:
|
Yeah, I'm going to look at it in a moment. |
I've merged a basic working version (043dc9a) including some tests. |
Wow! Merged in already? That was fast! On Sat, Mar 1, 2014 at 4:09 PM, Jurriaan Pruis notifications@github.comwrote:
|
i find rich_text.rb had been required in workbook.rb, but when i run myself test, i meet my code:
someone meet the same problem ??? |
Which version are you using? |
@jurriaan axlsx-2.0.1 thanks .. i install axlsx in rails's gemfile. |
RichText isn't released yet. You have to use the master branch to be able to use it.. |
@jurriaan thanks ... |
nice work on this! I added a RichText field and found it to be pretty easy to work with. |
@kenliu Thanks, I think this issue can be closed for now :) |
can this get put in a gem version? two years [with no activity] seems a long long time to... wait. |
When cell contains multi line text along with different partial format (bold, strike through or italic) than it doesn't work.
eg.
I have cell A1 with content as :
This is \b Bold the text \n This is the \strike Strike through the text.
\n, \t works fine but \b or \strike doesn't work. Can you guide me how to add partial style in multi line text cell?
As per this post, that 's avoiding those characters? #127.
The text was updated successfully, but these errors were encountered: