龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > VC开发 >

VC中对office的操作(5)

时间:2009-12-30 15:42来源:未知 作者:admin 点击:
分享到:
CArrayint,int maxcolwidarr; for(i = 0; i colNum; i++) ...{ int maxwid = tablestr[0][i].GetLength(); maxcolwidarr.Add(maxwid); for(j = 0; j rowNum; j++) ...{ if(tablestr[j][i].GetLength() maxcolwidarr[

    CArray<int,int&> maxcolwidarr;
    for(i = 0; i < colNum; i++)
    ...{
        int maxwid = tablestr[0][i].GetLength();
        maxcolwidarr.Add(maxwid);
        for(j = 0; j < rowNum; j++)
        ...{
            if(tablestr[j][i].GetLength() > maxcolwidarr[i])
                maxcolwidarr[i] = tablestr[j][i].GetLength();
        }
    }
    //填写标格
    for(int row = 1; row < rowNum+1; row++)
    ...{
        for(int col = 1; col < colNum+1; col++)
        ...{
            iCell = sheet.GetCells();
            iCell.SetItem(COleVariant((short )(row)),
                COleVariant((short )(col)),
                COleVariant(tablestr[row-1][col-1]));
            //iCell.SetColumnWidth(COleVariant((short)(maxcolwidarr[col-1])));
        }
    }
    //设置宽度
    for (int z = 0; z < maxcolwidarr.GetSize(); z++)
    ...{
        iCell.AttachDispatch(range.GetItem
            (COleVariant((long)1),COleVariant((long)(z+1))).pdispVal);
        iCell.SetColumnWidth (COleVariant((long)maxcolwidarr[z]));
    }

    //保存文件

    wbook.SaveAs(COleVariant(strOutExcelFile),
        COleVariant((short )(-4143)),
        COleVariant(""),
        COleVariant(""),
        COleVariant((short )(FALSE)),
        COleVariant((short )(FALSE)),
        0L,
        COleVariant((short )(NULL)),
        COleVariant((short )(NULL)),
        COleVariant((short )(NULL)),
        COleVariant((short )(NULL)));


    //return
    app.Quit();
    app.ReleaseDispatch();
    wbook.ReleaseDispatch();
    wbooks.ReleaseDispatch();
    sheet.ReleaseDispatch();
    sheets.ReleaseDispatch();
    range.ReleaseDispatch();
    iCell.ReleaseDispatch();
    win.ReleaseDispatch();
}

精彩图集

赞助商链接