java与vb代码对比

2017-5-18 玩者之心 原创

为实现依次从台帐表中提取数据填充到模板表中,并将结果另存到指定文件夹,分别采用java与vb编写代码如下:

void myfun(){//java代码

    Workbook wb,wbT,wbM=null;

    Worksheet shtT,shtM=null;

    wb  = Application.getWorkbooks().getActiveWorkbook();

    String path  = wb.getAbsolutePath().replaceFirst(wb.getName(),"");

    wbT  = Application.getWorkbooks().openWorkbook(path+"1_台帐_1.xls");

    wbM  = Application.getWorkbooks().openWorkbook(path+"2_模板_2.xls");

    shtT =wbT.getWorksheets().getWorksheet(1);

    shtM =wbM.getWorksheets().getWorksheet(1);

    for(int i=1;i<=10;i++){

        shtM.setCellValue(1,1,shtT.getCellValue(i,1));

        wbM.saveAs(path+"结果\\"+i+".xls");

    }

    wbM.close();

    wbT.close();

}

sub myfun()'vb代码

    dim wb as workbook,wbT as workbook,wbM as workbook

    dim shtT as worksheet,shtM as worksheet

    set wb=thisworkbook

    dim path as string : path =wb.path & "\"

    set wbT =workbooks.open(path & "1_台帐_1.xls")

    set wbM =workbooks.open(path & "2_模板_2.xls")

    set shtT=wbT.worksheets(1)

    set shtM=wbM.worksheets(1)

    for i =1 to 10

        shtM.cells(1,1)=shtT.cells(i,1)

        wbM.saveAs(path & "结果\" & i & ".xls")

    next

    wbM.close()

    wbT.close()

end sub

代码何其相似!

可见,语言只是工具,算法才是灵魂……

标签: java vb 算法

发表评论:


Copyright © onsed 黔ICP备15014640号-2