LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Excel: write text "00003589" in but it become number 3589

There is a problem when I use this function :ExcelRpt_WriteDataFromTableControl

 

I write a column of text data such as "00003589" and  "0000F689" to an excel , but when I done this , the data in the excel become "3589" and "0000F689"

 

I know the reason is all charter in "00003589" is number , but I don't konw how to solve it .

 

If I want to use ExcelRpt_WriteDataFromTableControl to realize this export. What should I do in addition ?

 

I use LabWindows CVI 9.0 and Excel 2007.

 

 

Thanks .

0 Kudos
Message 1 of 12
(5,921 Views)

As far as I can see by looking at ExcelReport instrument source code, the instrument writes cell by cell individually and determines the data type to write to Excel dependinog on cell type.

 

Can it be that your table cells are set as numeric with zero padding?

undefined

 



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 12
(5,921 Views)

Thanks for your reply.

 

My situation is not like this . Let me show you clearly.

 

1.I have an empty table

undefined

2.I have an excel like this 

undefined

3.I called function ExcelRpt_ReadDataToTableControl(worksheetHandle, cellRange, MakePoint(1,1), ExRConst_InsertRowAndColumn, cmdpanelHandle, PANEL_2_TABLE_3); and I got this 

 

undefined

4.My purpose is modify the date items in the table and export a new (not last import file) excel file (.xls)

so I used ExcelRpt_WriteDataFromTableControl(worksheetHandle, cellRange, cmdpanelHandle, PANEL_2_TABLE_3);

 

and I got an excel like this 

undefined

 

this is not what I want , I need 00007810. that is my problem ,Thank you very much.

0 Kudos
Message 3 of 12
(5,919 Views)

 It is quite clear that ''00001111" is a string I followed my program into function ExcelRpt_WriteDataFromTableControl

 

else if (cellType == VAL_CELL_STRING)
{
errChk (GetTableCellValLength (panel, control, cell, &intVal)); ---------------------------------1
charPtr = (char *) CA_AllocMemory ((intVal+1) * sizeof(char));  ---------------------------------2
if(!charPtr)
__caErrChk (E_OUTOFMEMORY);
errChk (GetTableCellVal (panel, control, cell, charPtr));             ---------------------------------3
__caErrChk (CA_VariantSetCString (&SetValueV, charPtr));     ---------------------------------4
CA_FreeMemory (charPtr);                                                               ---------------------------------5
charPtr = NULL;                                                                                  ---------------------------------6
}
else
{
__caErrChk (E_INVALIDARG);
}

__caErrChk (Excel_RangeSetItem (rangeHandle, ExcelRpt_GetErrorInfo(), CA_VariantInt(i+1), CA_VariantInt(j+1), SetValueV));  ---------------------------------7
CA_VariantClear (&SetValueV);

 

It is clearly that it is and string type.

 

0 Kudos
Message 4 of 12
(5,917 Views)

I tend to say that the problem is Excel trying to be "smart" Smiley Surprised

 

I have no real confirm on that, but I noticed that all dates (e.g. 2013-10-09) have been converted in another format (2013/10/9) while I suppose you are not doing anything about those cell format. This makes me think that Excel recognise those texts as dates and format them in some standard way it has in mind.

In the same way (I suppose) it recognises "00007810" as a number and applies that format, while "0009DDA" cannot be interpreted by the program as a hex number and is left as text.

 

I'm not sure whether it can fix the situation, but can you try to assign text format to the columns before importing data to Excel and see what happens?



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 5 of 12
(5,902 Views)

That is the problem of mine....I had konwn it is the problem caused by excel.

 

I have searched the way to set string fomate . But I havn't got it .

 

I only get the way of setting numeric fomate.

 

Do you know the function which can set the excel cell fomate to string to avoid "00003589" become number 3589  ?

 

Thank you very much ...

0 Kudos
Message 6 of 12
(5,873 Views)

I have figured out this problem , there must be a symbol "   '   "

 

That is to say , if  I want "00003589" in my excel cell, I should write "    '00003589      "

 

Thanks for your reply every time.

Message 7 of 12
(5,867 Views)

You're right: the single quote is the standard way to tell Excel to treat cell content as a text.

Glad you've found a solution to your problem.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 8 of 12
(5,852 Views)

 

hello,you can to send the project

0 Kudos
Message 9 of 12
(4,192 Views)

This thread is two years old, and the original poster has posted anything after those messages, I supposte you won't get eny response from him.

I suggest you to start a new thread explaining your problem so that somebody can offer some help.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 10 of 12
(4,177 Views)