Гость
Целевая тема:
Создать новую тему:
Автор:
Форумы / Java [игнор отключен] [закрыт для гостей] / Срочный совет. Почему не записывает? / 2 сообщений из 2, страница 1 из 1
05.09.2013, 15:41:08
    #38388086
eldarkaa
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Срочный совет. Почему не записывает?
Есть код
Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
package workhere;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.*;

public class WriterXlsx {
    public WriterXlsx(String sfilename, List<RecordNameCode> records, List<loadPerDay> planRecords, Integer days, Integer fullTime) {
        try ( FileInputStream fileInputStream = new FileInputStream("C:\\Users\\student3\\"+sfilename+".xlsx");)
        {
            int lastUsedColumn = createListHead().size();
            XSSFWorkbook workBook = new XSSFWorkbook(fileInputStream);
            XSSFSheet sheet = workBook.getSheetAt(0);
            cleaner(30,"",sheet);
            drawRecordHead(createListHead(),sheet);
            createPlanForDay(planRecords,days,fullTime,lastUsedColumn,sheet);
            writeContent(2, records,sheet);

            try(FileOutputStream out = new FileOutputStream("C:\\Users\\student3\\"+sfilename+".xlsx"); ) {
            workBook.write(out);
            out.close();         }


        } catch (IOException e) {
            e.printStackTrace();
        }

    }


    private List<String> createListHead(){
    }

    private List<String> createPlanHead(Integer day, Integer fullTime){ }

    public void createPlanForDay(List<loadPerDay> planRecords, Integer countDays, Integer fullTime,Integer lastUsedColumn, XSSFSheet sheet){
        int finishDays=countDays+1;
        int lastUsesColumn=lastUsedColumn;
        int day=1;
        while (day<finishDays){
            writePlanContent(lastUsesColumn,2,planRecords,sheet);
            lastUsesColumn = drawPlanHead(createPlanHead(day,fullTime),lastUsesColumn,sheet);
            day++;
        }

    }

    private void drawRecordHead(List<String> listRecordHead, XSSFSheet sheet){}

    private Integer drawPlanHead(List<String> listPlanHead,Integer lastUsedColumn, XSSFSheet sheet){ }

    public void writePlanContent(Integer lastUsedColumn, Integer displacement,List<loadPerDay> planRecords,XSSFSheet sheet){
        int lastUsesColumn=lastUsedColumn;
        int lastRow=planRecords.size();
        for (int lineId=0;lineId<lastRow;lineId++)   {
            Row row = sheet.createRow(lineId+displacement);
            loadPerDay record = planRecords.get(lineId);
            System.out.println("i: "+(lineId)+" column:"+(lastUsesColumn)+" wrote: "+record.getFullResource());
            row.createCell(lastUsesColumn).setCellValue(record.getFullResource());
            System.out.println("i: "+(lineId)+" column:"+(lastUsesColumn+1)+" wrote: "+record.getResourceForParty1());
            row.createCell(lastUsesColumn+1).setCellValue(record.getResourceForParty1());
            System.out.println("i: "+(lineId)+" column:"+(lastUsesColumn+2)+" wrote: "+record.getResourceForParty10());
            row.createCell(lastUsesColumn+2).setCellValue(record.getResourceForParty10());
            System.out.println("i: "+(lineId)+" column:"+(lastUsesColumn+3)+" wrote: "+record.getResourceForParty50());
            row.createCell(lastUsesColumn+3).setCellValue(record.getResourceForParty50());
        }
    }

    private void writeContent(Integer displacement, List<RecordNameCode> records,XSSFSheet sheet){}

    private void cleaner(Integer columnsCount, Object object, XSSFSheet sheet){}
    }



}


Проблема в этом куске кода
Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
    public void writePlanContent(Integer lastUsedColumn, Integer displacement,List<loadPerDay> planRecords,XSSFSheet sheet){
        int lastUsesColumn=lastUsedColumn;
        int lastRow=planRecords.size();
        for (int lineId=0;lineId<lastRow;lineId++)   {
            Row row = sheet.createRow(lineId+displacement);
            loadPerDay record = planRecords.get(lineId);
            System.out.println("i: "+(lineId)+" column:"+(lastUsesColumn)+" wrote: "+record.getFullResource());
            row.createCell(lastUsesColumn).setCellValue(record.getFullResource());
            System.out.println("i: "+(lineId)+" column:"+(lastUsesColumn+1)+" wrote: "+record.getResourceForParty1());
            row.createCell(lastUsesColumn+1).setCellValue(record.getResourceForParty1());
            System.out.println("i: "+(lineId)+" column:"+(lastUsesColumn+2)+" wrote: "+record.getResourceForParty10());
            row.createCell(lastUsesColumn+2).setCellValue(record.getResourceForParty10());
            System.out.println("i: "+(lineId)+" column:"+(lastUsesColumn+3)+" wrote: "+record.getResourceForParty50());
            row.createCell(lastUsesColumn+3).setCellValue(record.getResourceForParty50());
        }
    }


System.out для примера, так сказать - логирования. Да я плохо делаю, но так наглядно)
Result
Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
i: 0 column:7 wrote: 692
i: 0 column:8 wrote: 0
i: 0 column:9 wrote: 0
i: 0 column:10 wrote: 0
i: 1 column:7 wrote: 692
i: 1 column:8 wrote: 0
i: 1 column:9 wrote: 0
i: 1 column:10 wrote: 0
i: 2 column:7 wrote: 1384
i: 2 column:8 wrote: 0
i: 2 column:9 wrote: 0
i: 2 column:10 wrote: 0
i: 3 column:7 wrote: 0
i: 3 column:8 wrote: 0
i: 3 column:9 wrote: 0
i: 3 column:10 wrote: 0
i: 4 column:7 wrote: 346
i: 4 column:8 wrote: 0
i: 4 column:9 wrote: 0
i: 4 column:10 wrote: 0
i: 5 column:7 wrote: 346
i: 5 column:8 wrote: 0
i: 5 column:9 wrote: 0
i: 5 column:10 wrote: 0
i: 6 column:7 wrote: 2768
i: 6 column:8 wrote: 0
i: 6 column:9 wrote: 0
i: 6 column:10 wrote: 0
i: 7 column:7 wrote: 346
i: 7 column:8 wrote: 0
i: 7 column:9 wrote: 0
i: 7 column:10 wrote: 0
i: 8 column:7 wrote: 1384
i: 8 column:8 wrote: 0
i: 8 column:9 wrote: 0
i: 8 column:10 wrote: 0
i: 9 column:7 wrote: 1038
i: 9 column:8 wrote: 0
i: 9 column:9 wrote: 0
i: 9 column:10 wrote: 0
i: 10 column:7 wrote: 346
i: 10 column:8 wrote: 0
i: 10 column:9 wrote: 0
i: 10 column:10 wrote: 0
i: 11 column:7 wrote: 346
i: 11 column:8 wrote: 0
i: 11 column:9 wrote: 0
i: 11 column:10 wrote: 0
i: 12 column:7 wrote: 346
i: 12 column:8 wrote: 0
i: 12 column:9 wrote: 0
i: 12 column:10 wrote: 0
i: 13 column:7 wrote: 346
i: 13 column:8 wrote: 0
i: 13 column:9 wrote: 0
i: 13 column:10 wrote: 0
i: 14 column:7 wrote: 346
i: 14 column:8 wrote: 0
i: 14 column:9 wrote: 0
i: 14 column:10 wrote: 0
i: 15 column:7 wrote: 1730
i: 15 column:8 wrote: 0
i: 15 column:9 wrote: 0
i: 15 column:10 wrote: 0
i: 16 column:7 wrote: 346
i: 16 column:8 wrote: 0
i: 16 column:9 wrote: 0
i: 16 column:10 wrote: 0
i: 17 column:7 wrote: 346
i: 17 column:8 wrote: 0
i: 17 column:9 wrote: 0
i: 17 column:10 wrote: 0
i: 18 column:7 wrote: 346
i: 18 column:8 wrote: 0
i: 18 column:9 wrote: 0
i: 18 column:10 wrote: 0
i: 19 column:7 wrote: 692
i: 19 column:8 wrote: 0
i: 19 column:9 wrote: 0
i: 19 column:10 wrote: 0
i: 20 column:7 wrote: 1384
i: 20 column:8 wrote: 0
i: 20 column:9 wrote: 0
i: 20 column:10 wrote: 0
i: 0 column:11 wrote: 692
i: 0 column:12 wrote: 0
i: 0 column:13 wrote: 0
i: 0 column:14 wrote: 0
.............


Там записывает 4 столбца, потом по новой начинает, и так 14 раз.
Он мне прям пишет - я записал. Смотрю в xlsx там пусто. Что за баг? Все остальное нормально выводилось в xlsx.
Подскажите где искать, уже даже не знаю куда можно еще посмотреть или исправить.
доказательство что planRecords не пустой
Код: java
1.
2.
3.
            for (int i=0;i<planRecords.size();i++){
                System.out.println(planRecords.get(i).getFullResource()+" "+planRecords.get(i).getResourceForParty1()+" "+planRecords.get(i).getResourceForParty10()+" "+planRecords.get(i).getResourceForParty50());
            }

Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
692 0 0 0
692 0 0 0
1384 0 0 0
0 0 0 0
346 0 0 0
346 0 0 0
2768 0 0 0
346 0 0 0
1384 0 0 0
1038 0 0 0
346 0 0 0
346 0 0 0
346 0 0 0
346 0 0 0
346 0 0 0
1730 0 0 0
346 0 0 0
346 0 0 0
346 0 0 0
692 0 0 0
1384 0 0 0

...
Рейтинг: 0 / 0
05.09.2013, 17:20:51
    #38388229
eldarkaa
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Срочный совет. Почему не записывает?
если у кого будут проблемы) вспомните про крутую фишку createRow - очищение всей строки перед записью)
просто слов на нее не хватает!
спасибо всем кто не помог
...
Рейтинг: 0 / 0
Форумы / Java [игнор отключен] [закрыт для гостей] / Срочный совет. Почему не записывает? / 2 сообщений из 2, страница 1 из 1
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]