public void getExcelView(String fileName) {
ReleaseManager rm = new ReleaseManager();
try {
ExcelApplication excel = new ExcelApplication(rm);
ExcelWorkbooks xlBooks = excel.Workbooks();
ExcelWorkbook xlBook = xlBooks.Open(fileName);
ExcelWorksheet xlSheet = excel.ActiveSheet();
excel.Visible(true);
xlSheet.PrintOut(1, 2, 1, true);------------在这里,从第一页开始打印,有多个页面需要预览
xlBook.Close(false, null, false);
excel.Quit();
} catch (Exception e) {
e.printStackTrace(); } finally {
rm.release();
}
}
实际情况是可以打开Excel的预览窗口,而且下部消息栏也提示有2页,但是无法进行翻页,菜单栏的“上一页”、“下一页”都不可用,是灰色的!
请问如何实现翻页呢?

解决方案 »

  1.   

    public void getExcelView(String fileName, int page) {
    ReleaseManager rm = new ReleaseManager();
    try {
    ExcelApplication excel = new ExcelApplication(rm);
    ExcelWorkbooks xlBooks = excel.Workbooks();
    ExcelWorkbook xlBook = xlBooks.Open(fileName);
    ExcelWorksheet xlSheet = excel.ActiveSheet();
    excel.Visible(true);
    xlSheet.PrintOut(1, page, 1, true);
    xlBook.Close(false, null, false);
    excel.Quit();
    } catch (Exception e) {
    e.printStackTrace(); } finally {
    rm.release();
    }
    }
    太奇怪了,在调用这个方法时,如果用 getExcelView(fileName, 3);   就能正常显示翻页按钮,可以上下翻页
    但如果在调用时,page 换成一个变量的话,翻页按钮就无法使用,请问是什么问题呢?