05-23-2014 02:27 AM
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 .
05-23-2014 02:45 AM
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?
05-23-2014 03:04 AM
Thanks for your reply.
My situation is not like this . Let me show you clearly.
1.I have an empty table
2.I have an excel like this
3.I called function ExcelRpt_ReadDataToTableControl(worksheetHandle, cellRange, MakePoint(1,1), ExRConst_InsertRowAndColumn, cmdpanelHandle, PANEL_2_TABLE_3); and I got this
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
this is not what I want , I need 00007810. that is my problem ,Thank you very much.
05-23-2014 03:14 AM
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.
05-23-2014 05:45 AM
I tend to say that the problem is Excel trying to be "smart"
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?
05-25-2014 06:58 AM
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 ...
05-25-2014 10:34 PM
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.
05-26-2014 02:38 AM
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.
02-08-2016 05:37 PM
hello,you can to send the project
02-09-2016 02:14 AM
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.