Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.examples.hssf.usermodel;
  16. import java.io.FileOutputStream;
  17. import java.io.IOException;
  18. import org.apache.poi.hssf.usermodel.HSSFCell;
  19. import org.apache.poi.hssf.usermodel.HSSFRow;
  20. import org.apache.poi.hssf.usermodel.HSSFSheet;
  21. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  22. /**
  23. * Illustrates how to create cell values.
  24. *
  25. * @author Glen Stampoultzis (glens at apache.org)
  26. */
  27. public class CreateCells {
  28. public static void main(String[] args) throws IOException {
  29. try (HSSFWorkbook wb = new HSSFWorkbook()) {
  30. HSSFSheet sheet = wb.createSheet("new sheet");
  31. // Create a row and put some cells in it. Rows are 0 based.
  32. HSSFRow row = sheet.createRow(0);
  33. // Create a cell and put a value in it.
  34. HSSFCell cell = row.createCell(0);
  35. cell.setCellValue(1);
  36. // Or do it on one line.
  37. row.createCell(1).setCellValue(1.2);
  38. row.createCell(2).setCellValue("This is a string");
  39. row.createCell(3).setCellValue(true);
  40. // Write the output to a file
  41. try (FileOutputStream fileOut = new FileOutputStream("workbook.xls")) {
  42. wb.write(fileOut);
  43. }
  44. }
  45. }
  46. }