我写了一个测试代码: 其中的setPageStart函数总是设置无效,写完文件后自己打开excel文件,在页面设置中的起始页码还是“自动".
import java.io.File;
import java.io.FileOutputStream; 
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFPrintSetup;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 public class TestPoiWrite { /**
 * @param args
 */
public static void main(String[] args) {
 HSSFWorkbook workbook=null; 
 HSSFSheet sheet=null;   workbook = new HSSFWorkbook();  
 
 
 String[] contents = new String[]{"11", "22", "33"};
HSSFRow row ;
HSSFCell cell; 
HSSFPrintSetup   ps1 ;
int ROWCOUNT =0;

//写第一个工作表
sheet = workbook.createSheet(); 
 
row = sheet.createRow(ROWCOUNT++);  //创建一行
for (short i=0; i< contents.length; i++){
cell = row.createCell(i);  
cell.setCellType(HSSFCell.CELL_TYPE_STRING);//cell.setEncoding(HSSFCell.ENCODING_UTF_16); 
cell.setCellValue(new HSSFRichTextString(contents[i]));  
}  
//设置超始页
ps1   =   sheet.getPrintSetup(); 
ps1.getPageStart();
ps1.setPageStart((short)1); //无效,原因未知

//写第2个工作表
ROWCOUNT =0;
sheet = workbook.createSheet(); 
row = sheet.createRow(ROWCOUNT++);  
for (short i=0; i< contents.length; i++){
cell = row.createCell(i);  
cell.setCellType(HSSFCell.CELL_TYPE_STRING);//cell.setEncoding(HSSFCell.ENCODING_UTF_16); 
cell.setCellValue(new HSSFRichTextString(contents[i]));  
}  
//设置超始页
ps1   =   sheet.getPrintSetup(); 
ps1.setPageStart((short)0); //无效,原因未知


//文件输出
String filename = "c:\\test1.xls";
FileOutputStream fos =null; 
try{    
File f = new File(filename);
f.delete();
fos= new FileOutputStream(filename);
workbook.write(fos);
fos.flush();
fos.close();
fos=null;    
}catch (Exception e){
try{
if (fos!=null) fos.close();
}catch(Exception e1){
e1.printStackTrace();
}
 
}   
workbook = null;
}}