Writing some columns into another file

Hi all,

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.

Thanking You,

Regards,

Siva Ram

Hi Siva Ram,

Thanks for considering Aspose.

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);

Hopefully it will give you some insight.

Thank you.

Hi All,

Thanks for your response.

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.

Thanks All,

Regards,

SivaRam

Hi,

Thanks for considering Aspose.

I thought that you are using .Net version of Aspose.Cells. But you are using java version of Aspose.Cells component.

Please try the following code for java version:

import java.io.*;
import com.aspose.cells.*;

class GetFromTabDelimit
{


public static void main(String []args)
{

try
{

Workbook tabfile = new Workbook();
tabfile.open("E:\\Files\\TEST_FILE.txt",FileFormatType.TAB_DELIMITED);
Worksheet tabfilesheet = tabfile.getWorksheets().getSheet(0);

Workbook workbook = new Workbook();
Worksheet worksheet = workbook.getWorksheets().getSheet(0);
int i = 0;
for(int row = 0;row<=tabfilesheet.getCells().getMaxDataRow();row++)
{
if (tabfilesheet.getCells().getCell(row,2).getStringValue() != "")
{
worksheet.getCells().getCell(i,0).setValue(tabfilesheet.getCells().getCell(row,2).getStringValue());
i++;
}
}

workbook.save("E:\\Files\\tabfilexls.xls",FileFormatType.EXCEL2003);


}

catch(Exception ee)
{

System.out.println(ee);
}








}





}
Thank you.

Hi,

Please use Cells.copyColumn(Cells sourceCells, int sourceColumnIndex, int destinationColumnIndex) method .