jxl 읽기/쓰기 excel
5367 단어 JXL
boolean hsaNext = true;
Long pageNo = 1L;
int row = 1;
WritableWorkbook book = null;
WritableSheet sheet;
WritableCellFormat wcf_left;
try {
book = Workbook.createWorkbook(new File("d:/Test.xls"));
sheet = book.createSheet("Sheet_1", 0);
WritableFont BoldFont = new WritableFont(WritableFont.ARIAL, 10,
WritableFont.BOLD);
WritableFont NormalFont = new WritableFont(WritableFont.ARIAL, 10);
WritableCellFormat wcf_center = new WritableCellFormat(BoldFont);
wcf_center.setBorder(Border.ALL, BorderLineStyle.THIN);
wcf_center.setVerticalAlignment(VerticalAlignment.CENTRE); //
wcf_center.setAlignment(Alignment.CENTRE); //
wcf_center.setWrap(false); //
wcf_left = new WritableCellFormat(NormalFont);
wcf_left.setBorder(Border.NONE, BorderLineStyle.THIN); //
wcf_left.setVerticalAlignment(VerticalAlignment.CENTRE); //
wcf_left.setAlignment(Alignment.LEFT); //
wcf_left.setWrap(false); //
sheet.addCell(new Label(0, 0, " ", wcf_center));
sheet.addCell(new Label(1, 0, " ", wcf_center));
sheet.addCell(new Label(2, 0, " ", wcf_center));
sheet.addCell(new Label(3, 0, " ", wcf_center));
sheet.addCell(new Label(4, 0, " ", wcf_center));
sheet.addCell(new Label(5, 0, " ", wcf_center));
sheet.addCell(new Label(6, 0, " ", wcf_center));
sheet.addCell(new Label(7, 0, " ", wcf_center));
sheet.addCell(new Label(8, 0, " id", wcf_center));
while (hsaNext) {
TradesSoldGetRequest req = new TradesSoldGetRequest();
req.setFields("tid");
Date dateTime = null;
try {
dateTime = SimpleDateFormat.getDateTimeInstance().parse(
"2014-04-03 00:00:00");
} catch (ParseException e) {
e.printStackTrace();
}
req.setStartCreated(dateTime);
req.setStatus("TRADE_FINISHED");
req.setUseHasNext(true);
req.setPageSize(100L);
req.setPageNo(pageNo);
TradesSoldGetResponse response = null;
try {
response = client.execute(req, sessionKey);
hsaNext = response.getHasNext();
List<Trade> trades = response.getTrades();
Iterator<Trade> iterTrades = trades.iterator();
while (iterTrades.hasNext()) {
try {
Trade trade = iterTrades.next();
Trade fullTrade = topTradeWrapperService
.getFullInfoTrade(trade.getTid(),
sessionKey);
List<PromotionDetail> proDetails = fullTrade
.getPromotionDetails();
sheet.addCell(new Label(0, row, String
.valueOf(fullTrade.getTid()), wcf_left));
sheet.addCell(new Label(1, row, fullTrade
.getBuyerNick(), wcf_left));
sheet.addCell(new Label(2, row, fullTrade
.getPayment(), wcf_left));
sheet.addCell(new Label(3, row, SimpleDateFormat
.getDateTimeInstance().format(
fullTrade.getPayTime()), wcf_left));
sheet.addCell(new Label(4, row, fullTrade
.getDiscountFee(), wcf_left));
if (null != proDetails && !proDetails.isEmpty()) {
for (PromotionDetail promotionDetail : proDetails) {
sheet.addCell(new Label(5, row,
promotionDetail.getPromotionName(),
wcf_left));
sheet.addCell(new Label(6, row,
promotionDetail.getPromotionDesc(),
wcf_left));
sheet.addCell(new Label(7, row,
promotionDetail.getDiscountFee(),
wcf_left));
sheet.addCell(new Label(8, row,
promotionDetail.getPromotionId(),
wcf_left));
row++;
}
}
System.out.println(row);
row++;
} catch (Exception e) {
e.printStackTrace();
}
}
pageNo++;
} catch (ApiException e) {
e.printStackTrace();
try {
Thread.sleep(3000);
} catch (InterruptedException e1) {
}
}
}
book.write();
} catch (RowsExceededException e1) {
e1.printStackTrace();
} catch (WriteException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
} finally {
try {
book.close();
} catch (WriteException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
읽기:
Workbook book = null;
try {
book = Workbook.getWorkbook(new File(
"d:/gymboree .xls"));
Sheet sheet = book.getSheet(0);
String buyer = "";
List<String> delBuyer = new ArrayList<String>();
for (int i = 0; i < sheet.getRows(); i++) {
try {
Cell cell = sheet.getCell(1, i);
String buyerCell = cell.getContents();
if (StringUtils.isNotBlank(buyerCell)) {
buyer = buyerCell;
}
cell = sheet.getCell(6, i);
String couponCell = cell.getContents();
if (!delBuyer.contains(buyer) && couponCell.equals(" : 80.00 ")) {
User user = new User();
user.setNick(buyer);
delBuyer.add(buyer);
Long eId = couponCardServiceImpl.use(28539L, user);
System.out.println(eId);
}
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (BiffException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
book.close();
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Jxl Excel 파일 읽기 및 쓰기최근에 Excel 파일의 가져오기 내보내기를 사용하려고 합니다. Jxl과poi 두 가지 방식을 비교했습니다. Jxl은 상대적으로 간단하지만 xlsx 형식(2003 이전 버전)은 지원되지 않습니다. 다음은 Jxl의 데...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.