Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Gigi on Apr 16, 2008 06:55
open dhtmlx forum
TreeGrid

We are not able to cut and paste from excel where we have comma separated values. We have used the /t delimiter as advised but still the left truncation from the comma position is what is getting copied. Please advise on us on how to handle this and the main facility of copying values from excel will be lost if we are not able to do this function.
Answer posted by Support on Apr 16, 2008 09:34
>>We have used the /t delimiter a
The correct delimeter is  \t
    grid.setCSVDelimiter("\t")

If problem still occurs for you - please provide a js code which was used for grid initialization, because we can't reconstruct problem with local samples.
Answer posted by Gigi on Apr 17, 2008 02:50

The following is the code for initialising the grid

 

mygrid.setHeader("Grades,Comments,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec,Jan,Feb,Mar,Total");
   mygrid.setInitWidths("60,80,60,60,60,60,60,60,60,60,60,60,60,60,85");
   mygrid.setColTypes("ro,txt,ed,ed,ed,ed,ed,ed,ed,ed,ed,ed,ed,ed,ro[=c2+c3+c4+c5+c6+c7+c8+c9+c10+c11+c12+c13]");
   mygrid.setColAlign("left,left,right,right,right,right,right,right,right,right,right,right,right,right,right");
   mygrid.setColSorting("str,str,int,int,int,int,int,int,int,int,int,int,int,int,int");
   mygrid.setSkin("modern");
   mygrid.init();
   mygrid.setOnEditCellHandler(doOnCellEdit);
   mygrid.setOnKeyPressed(onKeyPressed);
      mygrid.enableBlockSelection();
   mygrid.attachFooter("Total,#cspan,<div id='ar_q' style='text-align:right'>0</div>,<div id='br_q' style='text-align:right'>0</div>,<div id='cr_q' style='text-align:right'>0</div>,<div id='dr_q' style='text-align:right'>0</div>,<div id='er_q' style='text-align:right'>0</div>,<div id='fr_q' style='text-align:right'>0</div>,<div id='gr_q' style='text-align:right'>0</div>,<div id='hr_q' style='text-align:right'>0</div>,<div id='ir_q' style='text-align:right'>0</div>,<div id='jr_q' style='text-align:right'>0</div>,<div id='kr_q' style='text-align:right'>0</div>,<div id='lr_q' style='text-align:right'>0</div>,<div id='mr_q' style='text-align:right'>0</div>",["text-align:left;"])
   mygrid.loadXMLString(xmlStringforGrid,calculateFooterValues);

 

"xmlStringforGrid" is the xml string for grid loading.

 

function onKeyPressed(code,ctrl,shift){

 if(code==67&&ctrl){
  mygrid.setCSVDelimiter("\t")
  var csvNew = mygrid.serializeToCSV();
  mygrid.copyBlockToClipboard();
 }

}

 

 

Answer posted by Support on Apr 17, 2008 05:17
Please check attached sample, it uses the same initialization code as in your case and there is no any problem to copy comma separated values from excel or into excel.
Attachments (1)
Answer posted by Gigi on Apr 24, 2008 23:27

Sorry, it didnt work with excel

Is there anything else to be modified other than setting CSV Delimiter to "\t"?

 

 

Answer posted by Support on Apr 25, 2008 01:48
>>Sorry, it didnt work with excel
Can you provide mode details, please.
Which version of Excel you are using and which data exactly can't be copied.
The same sample works fine in local test, while coping data with commas from grid to Excel, or from Excel to grid.

>>Is there anything else to be modified other than setting CSV Delimiter to "\t"
This is the only necessary step.
Answer posted by Gigi on Apr 25, 2008 03:02

 

I tried changing the column sort criteria from "int" to "str".

The code change was:

mygrid.setColSorting("str,str,str,str,str,str,str,str,str,str,str,str,str,str,str");

Then i could copy from Microsoft excel to dhtmlxtreegrid. But the row wise sum(ie, the column "Total" gives me "NaN"..perhaps, due to the "," .How can i get the rowwise total also in a "comma separated numerical value" format?

 

Answer posted by Support on Apr 25, 2008 08:09
So the problem is not in the incorrect data, but in not processing results of paste as int values, right ?
The problem is that grid can't recognize is inserted value a number with comma separated digits which need to be processed or just a string which must be set untouched.
While it not possible to do necessary conversion automatically it possible to implement necessary logic by using onRowPaste event - you can get the pasted value and replace the comma in it, so it will be correct for any in-grid math operations.

Please check attached sample.
Attachments (1)