I have a problem with copy rows. I have a folder with excel files, and I will copy all files A6:T35 cell to one excel files. My problem is, the last CellRange copyed just.
Pleas, help my, how can i all files cell copy to one sheet.
My code:
- Code: Select all
public class Masolo extends JFrame
{
private JPanel contentPane;
private int a = 6;
private int b = 1;
private int c = 35;
private int d = 20;
private int uja = 6;
private int ujb = 1;
private int ujc = 35;
private int ujd = 20;
private File mappa;
private File[] fajlok;
private Workbook workbook;
/**
* Launch the application.
*/
public static void main(String[] args)
{
EventQueue.invokeLater(new Runnable()
{
public void run()
{
try
{
Masolo frame = new Masolo();
frame.setVisible(true);
}
catch (Exception e)
{
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Masolo()
{
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JButton masolgomb = new JButton("Másolás");
masolgomb.setBounds(164, 89, 89, 23);
masolgomb.addActionListener(new Masol());
contentPane.add(masolgomb);
}
class Masol implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
mappa = new File("c:\\Users\\user_name\\Desktop\\teszt mappa\\mappa\\");
fajlok = mappa.listFiles();
Worksheet sheet2;
CellRange[] range2 = new CellRange[fajlok.length];
for(int szamlalo = 0; szamlalo < fajlok.length; szamlalo++)
{
//Create a Worbook instance
workbook = new Workbook();
//Load an Excel file
workbook.loadFromFile("c:\\Users\\user_name\\Desktop\\teszt mappa\\mappa\\" + fajlok[szamlalo].getName());
//Get the first worksheet
Worksheet sheet1 = workbook.getWorksheets().get(0);
sheet2 = workbook.getWorksheets().get(1);
//Specify the source cell range
CellRange range1 = sheet1.getCellRange(a,b,c,d);
//Specify the destination cell range
range2[szamlalo] = sheet2.getCellRange(uja,ujb,ujc,ujd);
//Copy a cell range from sheet 1 to sheet 2
//sheet1.copy(sheet1.getCellRange("A1:H1"),sheet2.getCellRange("A1:H1"),true);
//Copy the source cell range to the destination cell range
sheet1.copy(range1, range2[szamlalo]);
/*
for (int i = 0; i < 8; i++)
{
sheet2.autoFitColumn(i+1);
}
*/
//Save the result file
uja += 30;
ujc += 30;
System.out.println("Kész");
}
//Save the result file
workbook.saveToFile("c:\\Users\\user_name\\Desktop\\teszt mappa\\masol_teszt.xlsx", FileFormat.Version2013);
}
}
}