Column::SetNumRows

Description

Set the internal size of a Column. Columns in a worksheet can all have different sizes. One can use SetUpperIndex to control the visible rows, but can use this method to control the actual internal memory allocation.

Syntax

BOOL SetNumRows( int nRows )

Parameters

nRows
[input] Number of rows to set, nRows must larger than 0. If all rows are shown, then this number should be GetUpperIndex + 1

Return

Returns TRUE on successful exit and FALSE on failure.

Examples

EX1

//Before you run, put some data into col(1) or active worksheet
void    Column_SetNumRows_Ex1()
{
    Worksheet wks = Project.ActiveLayer();
        Column col(wks,0);
    printf("Before, col(1) has %d visible rows but has an internal size of %d\n", col.GetUpperIndex()+1, col.GetNumRows());
        vectorbase& vv = col.GetDataObject();
        vv.Data(1,10);
        col.SetNumRows(50);  // set column size to 50
    printf("After, col(1) has %d visible rows but has an internal size of %d\n", col.GetUpperIndex()+1, col.GetNumRows());
}

EX2

//This function frees up extra spaces in a workbook by trimming all the columns to their visible rows plus a few extra only.
//It prints out those columns that has a reduction of at least 'nDiffToReport' cells
void Column_SetNumRows_Ex2(int nDiffToReport = 500)
{
        WorksheetPage wp = Project.Pages(); // active window
        if(!wp)
                return;
        
        string strBookName = wp.GetName();
        
        foreach(Layer lay in wp.Layers)
        {
                Worksheet wks = lay;
                string strSheetName = wks.GetName();

                foreach(Column cc in wks.Columns)
                {
                        int nMaxRows = cc.GetNumRows();
                        int nVisible = cc.GetUpperIndex();
                        if(nMaxRows - nVisible > nDiffToReport)
                        {
                                string strBookSheetName = make_book_sheet_name(strBookName,strSheetName );
                                string strColLN = cc.GetLongName();
                                printf("%s!col(%s)\t%d\t%d\n", strBookSheetName, strColLN, nVisible, nMaxRows);
                        }
                        //to fix the size of col, must set this to be at least one bigger then index
                        cc.SetNumRows(nVisible + 10);// still give a few more rows extra
                }
        }
}

Remark

See Also

Column::GetNumRows | vectorbase::SetSize | Column::SetUpperIndex

Header to Include

origin.h