jspreadsheet / pro

Jspreadsheet Pro | The javascript spreadsheet
https://jspreadsheet.com/
15 stars 1 forks source link

Mask on individual cells #33

Closed MartinDawson closed 3 years ago

MartinDawson commented 3 years ago

First of all, thank you for the brilliant library. It's far better than the alternatives. I personally tried to implement my own before I found yours and had a terrible algorithm for updating the cells.

Could you please show me how to apply individual masking/formatting to cells and NOT to columns?

Here's what I have tried:

  const options = {
    data: [[300000]],
    cells: [{ mask: "#,##0,,.00" }],
  }

Any many variations of this but nothing formats correctly.

In your docs: https://jspreadsheet.com/v7/docs/quick-reference

It says here that both columns & cells accept a mask property but I can't find an example anywhere.

Here's my spreadsheet that I am trying to format to be prettier and more readable and (correct me if I'm wrong) I think the mask property should be for formatting it right?

image

Thank you!

hodeware commented 3 years ago

Hi Martin,

This example might help. https://jspreadsheet.com/v7/cases/payment-calculator

cells: { A1: { type:'text', mask: '$ #.##' } }

Let me know if you need more information.

MartinDawson commented 3 years ago

@hodeware Thank you, still having trouble though.

My percentages are in decimal format: 0.15 for example.

Previously I was using XLSX and this mask worked for me "0.00%" for excel, it would convert 0.15 to 15% for example.

I can't figure out the correct mask for jspreadsheet though. For example, this mask: mask: "000.00%", formats 0.15 to be -> 010.00%.

Whereas I need it to be 10.00%.

I cannot use type: percent either because then it just converts it to 0 and the formulas don't work for it.

I do not want to change the percentages to be non-decimals because they are used in the calculations in the formulas, so if I change the underlying data from 0.15 to 15 then my formulas will need changing.

I'm having troubles with other maskings too. It seems as though the masking solution isn't as extensive as XLSX or excel's is?

For example, this mask in excel: $#,##0.00,, with an input of: =146322000 will produce $146.32, whereas this just doesn't work in jspreadsheet.

Opened new bug issue for it: https://github.com/jspreadsheet/pro/issues/35