SheetJS / sheetjs

📗 SheetJS Spreadsheet Data Toolkit -- New home https://git.sheetjs.com/SheetJS/sheetjs
https://sheetjs.com/
Apache License 2.0
35.04k stars 8k forks source link

[Help me] cell writing not work! #595

Closed seunggabi closed 7 years ago

seunggabi commented 7 years ago

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 :)

SheetJSDev commented 7 years ago

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

seunggabi commented 7 years ago

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 :)

SheetJSDev commented 7 years ago

@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).

seunggabi commented 7 years ago

@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?

SheetJSDev commented 7 years ago

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.

2) 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.

seunggabi commented 7 years ago

@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 commented 7 years ago

@SheetJSDev

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

it is cool!

gdoteof commented 7 years ago

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

superlbr commented 6 years ago

@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

kamthe commented 6 years ago

@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.

gdoteof commented 6 years ago

@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"
      },
superlbr commented 6 years ago

@ 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 commented 6 years ago

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

gdoteof commented 6 years ago

@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)

superlbr commented 6 years ago

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

gdoteof commented 6 years ago

@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

superlbr commented 6 years ago

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

seunggabi commented 6 years ago

@gdoteof thanks~ I agree your comment.

sky172839465 commented 5 years ago

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
gdoteof commented 5 years ago

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