LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

how to set excel column width

Solved!
Go to solution

I am using ExcelRpt_SetCellRangeAttribute function to set the width of a cell in excel.

What vale I should pass to set the width for example 50, I have tried to pass values  but its not working.

As a result of passing values the column containing that cell am specifying is getting hided.

pls help me out

0 Kudos
Message 1 of 8
(5,801 Views)

The value you are giving to the function, is it an integer? In that case, try to give the value in the form of a double.

0 Kudos
Message 2 of 8
(5,780 Views)

Hi Sumit,

 

I have tried with long,float,int & double but its not working.

I am using function

ExcelRpt_SetCellRangeAttribute(worksheethandle,Rangevalue,ER_CR_ATTR_COLUMN_WIDTH,widthvalue)

 

 

0 Kudos
Message 3 of 8
(5,771 Views)
0 Kudos
Message 4 of 8
(5,761 Views)

I have gone through this....its showing data type decimal for widthvalue, am trying to pass same but as a result the whole column is getting hided.

0 Kudos
Message 5 of 8
(5,757 Views)
Solution
Accepted by a kumar

Hi!

 

I modified the example project "excel2000dem.prj" come with LabWindows/CVI installation to see if I can set the column width as you asked.

 

Following partial code successfully set the column width to 15.0 points in MS Excel 2003.

 

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

#define EXCEL_ARRAY_OF_CELLS "A2:H11"

...

 

static ExcelObj_App               ExcelAppHandle = 0;      
static ExcelObj_Workbooks         ExcelWorkbooksHandle = 0;
static ExcelObj_Workbook          ExcelWorkbookHandle = 0; 
static ExcelObj_Window            ExcelWindowHandle = 0;   
static ExcelObj_Sheets            ExcelSheetsHandle = 0;   
static ExcelObj_Worksheet         ExcelWorksheetHandle = 0;
static ExcelObj_Range             ExcelRangeHandle = 0;    

static VARIANT MyCellRangeV;

 


....... (I assume you have an opened Excel application and a Workbook active already) .....


{  

    // Get Active Workbook Sheets
    error = Excel_GetProperty (ExcelAppHandle, NULL, Excel_AppSheets, CAVT_OBJHANDLE, &ExcelSheetsHandle);
               
    // Get First Sheet
    error = Excel_SheetsItem (ExcelSheetsHandle, NULL, CA_VariantInt(1), &ExcelWorksheetHandle);
       
    // Make First Sheet Active - should already be active   
    error = Excel_WorksheetActivate (ExcelWorksheetHandle, NULL);
  

    // Open new Range for Worksheet
    error = CA_VariantSetCString (&MyCellRangeV, EXCEL_ARRAY_OF_CELLS);
    error = Excel_WorksheetRange (ExcelWorksheetHandle, NULL, MyCellRangeV, CA_DEFAULT_VAL, &ExcelRangeHandle);

   

    // Make range Active   
    error = Excel_RangeActivate (ExcelRangeHandle, &ErrorInfo, NULL);

   

   // Set column width
    error = Excel_SetProperty (ExcelRangeHandle, &ErrorInfo, Excel_RangeColumnWidth, CAVT_DOUBLE, 15.0);
   

  ..........
}

 

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------- 

 

Let us know if this works for you.

 

Message 6 of 8
(5,735 Views)

Thanks,

I modified my code with these function its working.

0 Kudos
Message 7 of 8
(5,711 Views)

For what it's worth, simply passing a float value as the column width does work for me:

 

ExcelRpt_SetCellRangeAttribute(workSheet, "A1", ER_CR_ATTR_COLUMN_WIDTH, 25.0));

The advantage of this over the proposed solution is that you then don't have to attach the excel2000.h at all and instead use the ExcelReport.h exclusively.

0 Kudos
Message 8 of 8
(4,428 Views)