LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with Seting background colour & Text alignment of a range of cells in excel

I am using 1> ExcelRpt_SetCellRangeAttribute(gl_ExcelWorksheetHandle,s_RangeValue,ER_CR_ATTR_BGCOLOR,ptr_l_ColVal); function to set the background colour for a range of cells with valid colour value passing through ptr_l_ColVal , but its not setting the background colour with colour passed by me, all the time its setting with same colour blue/dark blue 2> ExcelRpt_SetCellRangeAttribute(gl_ExcelWorksheetHandle,s_RangeValue,ER_CR_ATTR_VERT_ALIGN,ptr_l_Verticalval); This CVI function I am using to set cell alignment but its not setting the alignment with specifed value passed by me in ptr_l_Verticalval The values are: ExRConst_HAlignCenter (-4108) ExRConst_HAlignCenterAcrossSelection (7) ExRConst_HAlignDistributed (-4117) ExRConst_HAlignFill (5) ExRConst_HAlignGeneral (1) ExRConst_HAlignJustify (-4130) ExRConst_HAlignLeft (-4131) ExRConst_HAlignRight (-4152) these are for horizontal alignment and ExRConst_VAlignBottom (-4107) ExRConst_VAlignCenter (-4108) ExRConst_VAlignDistributed (-4117) ExRConst_VAlignJustify (-4130) ExRConst_VAlignTop (-4160) these for vertical alignment Am passing one of these value to set alignment but its doing nothing ,each time am getting default alignment that was already there
0 Kudos
Message 1 of 6
(3,485 Views)

Kumar,

 

I modified part of the example "excel2000demo.c" shipped with CVI to realize what you wanted.

 

Assuming you've done this part already in your code

 

   static ExcelObj_Workbooks         ExcelWorkbooksHandle = 0;

   static VARIANT MyCellRangeV;

   ....

   .... (open Excel and activate an Excel worksheet ...)

   CA_VariantSetCString (&MyCellRangeV, "A2:H11");

 

 

1) To set the text alignment in a range of cells:

 

Excel_WorksheetRange (ExcelWorksheetHandle, NULL, MyCellRangeV, CA_DEFAULT_VAL, &ExcelRangeHandle);

Excel_RangeActivate (ExcelRangeHandle, &ErrorInfo, NULL);

Excel_SetProperty (ExcelRangeHandle, &ErrorInfo, Excel_RangeHorizontalAlignment, CAVT_INT, ExcelConst_xlHAlignRight);

Excel_SetProperty (ExcelRangeHandle, &ErrorInfo, Excel_RangeVerticalAlignment, CAVT_INT, ExcelConst_xlVAlignCenter);

 

 

2) To set the background color of a range of cells:

 

CAObjHandle  rangeInteriorHandle = 0 ;

 

Excel_GetProperty (ExcelRangeHandle, &ErrorInfo, Excel_RangeInterior, CAVT_OBJHANDLE, &rangeInteriorHandle);
Excel_SetProperty (rangeInteriorHandle, &ErrorInfo, Excel_InteriorColor, CAVT_INT, 0x00FFFF);     // yellow background

                 // Note: 0xFF0000=Blue, 0x00FF00=Green, 0x0000FF=Red 
   

 

These function calls work perfectly in my Excel 2003 version.

 

0 Kudos
Message 2 of 6
(3,451 Views)

Hi dcl,

 

I am using functions exposed by CVI i.e. 

ExcelRpt_SetCellRangeAttribute(gl_ExcelWorksheetHandle,s_RangeValue,ER_CR_ATTR_BGCOLOR,ptr_l_ColVal)

 

if I will use Excel_SetProperty,there is no help provided for these functions , so its very difficult to identify some parameters  in this function

0 Kudos
Message 3 of 6
(3,433 Views)

You're right.  There's not much help one could find from NI except those example programs.

You need to go to Microsoft's web sites and search for the programming help on Excel using Visual Basic.

And, of course, trial and error. 

 

0 Kudos
Message 4 of 6
(3,398 Views)

Thanks every one I got the solution....

0 Kudos
Message 5 of 6
(3,299 Views)

A Kumar:

 

If you found a solution different than what DCL9000 suggested, please post it.  If DCL9000 answered your question, mark that answer as the solution.

 

Thanks!

0 Kudos
Message 6 of 6
(3,274 Views)