21 Ekim 2019 Pazartesi

POI Excel XSSFWorkbook Sınıfı

Giriş
Şu satırı dahil ederiz.
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
Bu sınıf constructor kullanarak veya WorkbookFactory tarafından yaratılabilir.

Şeklen şöyle



constructor
Şöyle yaparız.
XSSFWorkbook workbook = new XSSFWorkbook();
constructor - File
Şöyle yaparız.
File file = ...;
Workbook workbook = new XSSFWorkbook(file);
constructor - InputStream
Şöyle yaparız
InputStream ftpIs = ...;
Workbook workbook = new XSSFWorkbook(ftpIs);
addPicture metodu
Şöyle yaparız
Workbook wb1 = new XSSFWorkbook();
Sheet sh = wb1.createSheet();
int picIdx = wb1.addPicture(getSamplePng(), Workbook.PICTURE_TYPE_PNG);
close metodu
Açıklaması şöyle.
Note - if the Document was opened from a File rather than an InputStream, you must write out to a different file, overwriting via an OutputStream isn't possible
Şu kod mevcut dosyayı açıp değişiklik yapıp tekrar kaydetmez.
InputStream is= new FileInputStream(file);
XSSFWorkbook  wb = new XSSFWorkbook(is);
...
FileOutputStream out = new FileOutputStream(file);  
wb.write(out);
out.close();
createSheet metodu
Şöyle yaparız.
XSSFSheet sheet = workbook.createSheet("mysheet");
getSheetAt metodu
Şöyle yaparız.
Sheet oldSheet = workbook.getSheetAt(0);
getSheetName metodu
Şöyle yaparız.
String sheetName = workbook.getSheetName(0);
write metodu
Şöyle yaparız.
FileOutpuStream out = ...;
workbook.write(out);
out.close()


17 Ekim 2019 Perşembe

POI Word XWPFTableRow Sınıfı

getTableCells metodu
Şöyle yaparız.
XWPFTableRow tableRow = ...
for (XWPFTableCell cell : tableRow.getTableCells()) {
  for(XWPFParagraph paragraph : cell.getParagraphs()) {               
    for (XWPFRun run : paragraph.getRuns()) {
      run.setText("Cell"+j++,0);
    }           
  }       
}

ListUtils Sınıfı

emptyIfNull metodu
Verilen  parametre null ise boş liste döner. CollectionUtils sınıfında da benzer bir metod var.

indexOf metodu
Java'daki List.indexOf() metodu halen predicate ile kullanılamıyor. Bu eksikliği kapatmak için bu metod ideal.

Örnek
Şöyle yaparız.
int index = ListUtils.indexOf(schedule, object -> object.getCity().equals(station));
partiton metodu
Örnek
Şöyle yaparız
int batch_size = 1000;
List<Integer> numbers = IntStream.rangeClosed(1, 11100)
  .boxed().toList();
List<List<Integer>> partition = ListUtils.partition(numbers, batch_size);
partition.forEach(System.out::println);
select metodu

Belirtilen kritere göre seçme yaparak yeni bir liste döndürür.
Örnek
Şöyle yaparız.
List<AgenceVO> vListeAgences = ...;

List<AgenceVO> vListeAgencesTrouvees = ListUtils.select(vListeAgences,
  new Predicate<AgenceVO>() {...}
);
union metodu
İki listeyi birleştirerek yeni bir liste döner.
Örnek
Şöyle yaparız.
List<String> newList = ListUtils.union(list1, list2);


15 Ekim 2019 Salı

AutoCloseInputStream Sınıfı

constructor
Şöyle yaparız.
InputStream content = new AutoCloseInputStream(stream);

Range Sınıfı

Giriş
Açıklaması şöyle.
"An immutable range of objects from a minimum to maximum point inclusive."
"The objects need to either be implementations of Comparable or you need to supply a Comparator."
between metodu
Range nesnesi döner.
Örnek
Şöyle yaparız.
Range.between(100, 200);
contains metodu
Şöyle yaparız.
Range<Integer> myRange = Range.between(100, 500);
if (myRange.contains(200)){
  // do something
}