Skip to content
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

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gazedreamily
Copy link
Collaborator

@gazedreamily gazedreamily commented Aug 31, 2023

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

Copy link
Contributor

@zyc9012 zyc9012 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@gazedreamily
Copy link
Collaborator Author

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!

@zyc9012
Copy link
Contributor

zyc9012 commented Sep 6, 2023

@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}`]

@gazedreamily
Copy link
Collaborator Author

@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

@zyc9012
Copy link
Contributor

zyc9012 commented Sep 11, 2023

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

@gazedreamily
Copy link
Collaborator Author

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

@zyc9012
Copy link
Contributor

zyc9012 commented Sep 11, 2023

@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

@gazedreamily
Copy link
Collaborator Author

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

@zyc9012
Copy link
Contributor

zyc9012 commented Sep 16, 2023

@gazedreamily That's exactly what I did

@gazedreamily
Copy link
Collaborator Author

@zyc9012 Oh! My fault, you are right!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants