10-18-2010 05:09 AM
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
Solved! Go to Solution.
10-19-2010 01:22 AM
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.
10-19-2010 04:27 AM
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)
10-19-2010 07:39 AM
Please take a look at the following link
10-19-2010 07:51 AM
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.
10-19-2010 08:35 PM
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.
10-20-2010 05:28 AM
Thanks,
I modified my code with these function its working.
07-28-2016 02:11 PM
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.