fortune-sheet icon indicating copy to clipboard operation
fortune-sheet copied to clipboard

fix: copy number with text format to a cell with text format

Open gazedreamily opened this issue 1 year ago • 9 comments

copy number with text format to a cell with text format will not auto generate cell type

  • before: When we copy "001" to a cell with text format, the cell will be convert to a number type and the value will be "1".

  • after The cell will stay text format and the number will still stay "001".

gazedreamily avatar Aug 31 '23 06:08 gazedreamily

Thanks @gazedreamily

Let's make it more general rather than being specific to ".fa === '@'"

Check if the cell has ct, if so, use update to generate the mask, otherwise, use generate

Thaks for your advice!

gazedreamily avatar Sep 06 '23 09:09 gazedreamily

@gazedreamily I don't think you get what I mean. [txt, flowdata[r + minh][c + minc]?.ct, txt], here m and v should always be generated instead of just being assigned with raw data, except it's a plain text. This is my impl. Kindly check if it's expected.

diff --git a/packages/core/src/events/paste.ts b/packages/core/src/events/paste.ts
index 54641b0..8c51af7 100644
--- a/packages/core/src/events/paste.ts
+++ b/packages/core/src/events/paste.ts
@@ -318,6 +318,14 @@ function pasteHandler(ctx: Context, data: any, borderInfo?: any) {
           value = data[h - minh][c - minc];
         }
 
+        if (x[c]?.ct?.fa != null && x[c]?.ct?.fa !== value.ct?.fa) {
+          value.m = update(x[c]?.ct?.fa!, value.raw || value.v);
+          value.ct = x[c]?.ct;
+          if (x[c]?.ct?.t === "s" && value.raw) {
+            value.v = value.raw;
+          }
+        }
+        delete value.raw;
         x[c] = value;
 
         if (value != null && x?.[c]?.mc) {
@@ -1782,6 +1790,8 @@ export function _handlePaste(ctx: Context, htmlText?: string, plainText?: string
               [cell.m, cell.ct, cell.v] = mask;
             }
+            // @ts-ignore
+            cell.raw = txt;
             const styleString =
               typeof allStyleList[`.${className}`] === "string"
                 ? allStyleList[`.${className}`]

zyc9012 avatar Sep 06 '23 10:09 zyc9012

@zyc9012 I think that we shouldn't change the format which the user set to the cell. I do the steps in Excel.

  1. select A1 and set its type into percentage
  2. input aaaa to A1
  3. the cell type of A1 is still percentage and the cell displays as aaaa

gazedreamily avatar Sep 11 '23 02:09 gazedreamily

@gazedreamily We are talking about paste here. Try pasting a string to the percentage cell.

zyc9012 avatar Sep 11 '23 06:09 zyc9012

@zyc9012 It is still percentage after I pasting a aaa value from a txt file

gazedreamily avatar Sep 11 '23 06:09 gazedreamily

@gazedreamily I tried several scenarios

  • If the source is plain text, e.g. copied from Notepad, the format is unchanged
  • If the source is HTML, e.g. copied from a web page, the format is changed
  • If the source is a table, e.g. copied from Google Sheets, the format is changed

zyc9012 avatar Sep 11 '23 08:09 zyc9012

@zyc9012 change the type of the cell before copy a value into it

gazedreamily avatar Sep 11 '23 09:09 gazedreamily

@gazedreamily That's exactly what I did

zyc9012 avatar Sep 16 '23 08:09 zyc9012

@zyc9012 Oh! My fault, you are right!

gazedreamily avatar Sep 18 '23 02:09 gazedreamily