How can i copy/paste text from ComboBox

Posted by: ngocnguyen09910060 on 10 February 2022, 2:10 am EST

  • Posted 10 February 2022, 2:10 am EST

    Hi teams,

    On my web application, i setting: clipBoardOptions = GC.Spread.Sheets.ClipboardPasteOptions.values
    I have a combobox with editorValueType = value.

    Now, i want to copy/paste text from combobox to another cell but it copy/paste value.

    How can i do it ?
  • Replied 10 February 2022, 10:33 pm EST

    Hi,

    We have tested with clipboardOptions set to GC.Spread.Sheets.ClipboardPasteOptions.values and comboBox editor value type is set to EditorValueType.value and it seems to be working fine. You can Simply copy/paste using Ctrl+C/Ctrl+V or use the context menu to copy the cell and paste into another cell(paste value).
    Please refer to the following sample and let us know if you face any further issues: https://jscodemine.grapecity.com/share/VhYltUsgUkuvGgPWM7T_-Q/

    Regards
  • Replied 11 February 2022, 3:23 am EST

    Hi ankit.kumar,

    In your sample, when i paste, result is: 11k/15k/100k.
    I want to paste text: Oranges/Apples/Grape.
    How can i do it ?

    Regards
  • Replied 13 February 2022, 4:39 pm EST

    Hi,

    For this, you need to change the editValueType to text. Please refer to the following code snippet and let me know if you face any issues.


    var combo = new spreadNS.CellTypes.ComboBox();
    combo.items([{ text: "Oranges", value: "11k" }, { text: "Apples", value: "15k" }, { text: "Grape", value: "100k" }])
    .editorValueType(spreadNS.CellTypes.EditorValueType.text);
    sheet.getCell(1, 2, spreadNS.SheetArea.viewport).cellType(combo).value("Oranges");


    API:

    editorValueType: https://www.grapecity.com/spreadjs/docs/v14/online/SpreadJS~GC.Spread.Sheets.CellTypes.ComboBox~editorValueType.html

    Regards,
    Avinash
  • Replied 14 February 2022, 1:57 pm EST

    Hi ankit.kumar,

    If i using EditorValueType.text, when end user click button Save, i get value of cell:
    sheet.getCell(idxRow, idxCell).value()
    it return Oranges/Apples/Grape. But i want to call API Save with 11k/15k/100k.
    Please help me.

    Regards
  • Replied 14 February 2022, 4:06 pm EST

    Hi,

    editorValueType sets the value that is written to the underlying data model. You can use the sheet.getValue() to get the value of the underlying data model.
    Considering your use case, you can override the copy command so that it will paste the text when copy/pasting the combobox and get you the combobox's value using sheet.getValue()
    getValue Method: https://www.grapecity.com/spreadjs/docs/v14/online/SpreadJS~GC.Spread.Sheets.Worksheet~getValue.html
    Please refer to the sample that I have created for you and let us know if you face any further issues: https://jscodemine.grapecity.com/share/nIRGfOaqJkCiJuhPgUAuBg/

    Regards.
  • Replied 15 February 2022, 11:38 pm EST

    Hi ankit.kumar,

    I have downloaded your sample code and started success.
    But my project is using TypeScript and when i apply your code:
    oldFn.apply(this, arguments);

    I get error:
    Argument of type 'IArguments' is not assignable to parameter of type '[context: Workbook, options: { sheetName: string; }]'.


    Please help me.
  • Replied 16 February 2022, 4:36 pm EST

    Hi,

    You can overcome this error by simply using
     (oldFn as any).apply(this, arguments); 
    and it will work fine.

    Regards.
  • Marked as Answer

    Replied 16 February 2022, 10:44 pm EST

    Hi ankit.kumar,

    It work fine.

    Thank you very much.
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels