I need a small help. i have one (*.xls) file which is in text tab delimited format.i want to read only some columns from the file and want to write it on another (*.xls) file which is in excel work book format.i am very new to this api.please help me how to write this data into another file.
Well, you may try to use Cells.PutValue(value) to insert data into the cells of the worksheet in the excel file (.xls) from the tab delimited text file.
May the following example code helps you for your need.
//Instantiate and open the tab delimited text file. Workbook tabfile = new Workbook(); tabfile.Open("d:\\test\\TEST_FILE.txt",FileFormatType.TabDelimited); Worksheet tabfilesheet = tabfile.Worksheets[0];
//Open a template excel file. Workbook workbook = new Workbook(); workbook.Open("d:\\test\\mybook.xls", FileFormatType.Excel2003); Worksheet worksheet = workbook.Worksheets[0]; int i = 0; //Fetch the third column C from the tab delimited text file. for(int row = 0;row<=tabfilesheet.Cells.MaxDataRow;row++) { if (tabfilesheet.Cells[row,2].StringValue != "") { //Input data into the first column cells in the worksheet of the workbook //from all the cells in the third column C of the tab delimited sheet. worksheet.Cells[i,0].PutValue(tabfilesheet.Cells[row,2].StringValue); i++; } } //Save as the excel file. workbook.Save("d:\\test\\mybook1.xls",FileFormatType.Excel2003);
i tried your code but my api didn't find any method given in that code.for example there is no method like Worksheets for workbook object.similiary there is no pubvalue method for cells object.i am using jdk 5.0 version jars.please guide to to resolve this problem.