sheetjs icon indicating copy to clipboard operation
sheetjs copied to clipboard

[Help me] cell writing not work!

Open seunggabi opened this issue 9 years ago • 20 comments

Hello. I have a issue the issue is [enter key] not working cell

asdf[enter]asdf
==== cell update ===> asdf asdf

I don't understand. this was situation.... I need your help..

In fact, I am making Excel Merge Tool(EMT) https://github.com/seunggabi/excel-merge-tool If you help, you can make it successful.

I will wait for your help :)

seunggabi avatar Mar 14 '17 13:03 seunggabi

@seunggabi What do you mean by "enter key"? are you trying to insert a newline "\n" in a cell?

SheetJSDev avatar Mar 14 '17 18:03 SheetJSDev

Yes, I am

[now..] "asdf"+String.fromCharCode(13)+"asdf" => asdf asdf ====excel file open & cell update====> asdf\nasdf

@SheetJSDev I will wait for your help :)

seunggabi avatar Mar 15 '17 13:03 seunggabi

@seunggabi we will have an answer soon. The different formats treat the character codes 0x0A and 0x0D in subtly different ways, mainly because Excel isn't entirely consistent.

(related https://github.com/SheetJS/js-xlsx/issues/108).

SheetJSDev avatar Mar 16 '17 01:03 SheetJSDev

@SheetJSDev Thanks you sir.

I understand your word. You told me, it(\n update issue) is not working, however You will have an answer soon. isn't it?

seunggabi avatar Mar 16 '17 04:03 seunggabi

Ok I looked into this a bit. There are two parts.

  1. what character should be used?

ODS/FODS accept either \n or \r based on my tests, whereas Excel only accepts \r.

  1. how do you get excel to show multiple lines?

If you do that, the cell won't show up in 2 lines but you can select the cell and enable "Wrap Text" (right-click the cell, go to format cells, then "Alignment" tab then check "Wrap Text") and you will see it display as multiple lines.

This is written as part of the cellXfs block which is something we need to support.

SheetJSDev avatar Mar 16 '17 22:03 SheetJSDev

@SheetJSDev

Okay, I understand your word. I appreciate your tips No.2

I learned 'Wrap Text' because of you. If I need help, I'll ask you another question.

seunggabi avatar Mar 20 '17 04:03 seunggabi

@SheetJSDev

Thank you! I solved it. cell.s = {wrapText: true}

it is cool!

seunggabi avatar Apr 20 '17 09:04 seunggabi

In case anyone else comes here looking for wrapText, @seunggabi solution was not quite right.

cell.s = {alignment:{ wrapText: true }} works for me. as seen here:

https://github.com/SheetJS/js-xlsx/blob/935821423f2ff83412f39aac9ee201e975351978/bits/47_styxml.js#L307

gdoteof avatar Aug 15 '17 16:08 gdoteof

@gdoteof would you please give an example, it just not work for me.
\r also not work, I have to click the cell so to split. bookSST seems unrelated

superlbr avatar Apr 24 '18 03:04 superlbr

@gdoteof, Can you please tell me which file do i need to refer for wrapping the text in cell? i am using xlsx.full.min.js. but it is not applying any style for the generated excel file.

kamthe avatar May 02 '18 10:05 kamthe

@superlbr and @kamthe

Sorry for the messy thoughts here; I am just waking up and haven't really touched any of this in about a year. AND -- it's all very, very messy.

That being said I believe both of your issues are related to the fact that you are using the wrong js-xlsx. There are two (this repo) and and js-xlsx-style which actually has styling semi-well implemented.

Could you please retry either using my fork here: https://github.com/gdoteof/js-xlsx

or the (original?) js-xlsx-style fork here: https://github.com/protobi/js-xlsx

@superlbr the example you are looking for here is here:

https://github.com/protobi/js-xlsx/issues/16

specifically you would be looking to do something like

      "A1": {
        "v": "CELL TEXT HERE ",
        "s": {
          "alignment": {
            "wrapText": 1,
          }
        },
        "t": "s"
      },

gdoteof avatar May 02 '18 17:05 gdoteof

@ gdoteof not work yet.

  1. use '\r', then x000d will show in my mobile browser
  2. write as protobi#16, not work though. should I use protobi/js-xlsx?

superlbr avatar May 03 '18 02:05 superlbr

I find an example https://codepen.io/superlbr/pen/bMEXGE?editors=0111, but don't know how it work...

superlbr avatar May 03 '18 02:05 superlbr

@superlbr if you are just trying to do lines, \n should work fine.

Only use the protobi version if you need styling (colors and borders and stuff)

gdoteof avatar May 03 '18 03:05 gdoteof

@ gdoteof use \n , I need to click the cell to edit, then it wrap...

superlbr avatar May 03 '18 03:05 superlbr

@superlbr sorry I didn't understand. The answer is yes, this will not work for you (this word wrapping is considered styling which is not supported in this. Use the protobi version if you want styling.

Does this one do wwhat you want? https://codepen.io/gdoteof/pen/aGwBrL?editors=1111

gdoteof avatar May 03 '18 03:05 gdoteof

yes, it works. Seems little difference between web side and server side.

superlbr avatar May 03 '18 06:05 superlbr

@gdoteof thanks~ I agree your comment.

seunggabi avatar Aug 17 '18 03:08 seunggabi

Thanks @gdoteof 's demo ! However it seems broken, after fix broken code it work for me ! Using xlsx-style instead of xlsx, and wrap line (A4) work perfect !

螢幕快照 2019-03-24 下午1 23 47

sky172839465 avatar Mar 24 '19 05:03 sky172839465

thanks @sky172839465 i am not sure why i had that type hinting thing in there that was broken. i updated the gist in case anyone else comes to it

gdoteof avatar Mar 26 '19 13:03 gdoteof