本文介绍了在读取打开的办公室电子表格时识别列中的空白单元格并显示它们而不插入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的代码,用于读取开放式办公室电子表格数据,其中我有16列,问题是16列,我有第14列,其中数据不能为空第14列(如果有任何单元格)是空的我应该显示一个错误消息,通过显示该列的行号,这些行是空的请填写,如果所有单元格都填入该列,数据应插入数据库我怎么能这样做任何人可以帮助我我不喜欢这个







public void readODS(文件档案)

{

表单;

试试

{

//获取第0张表格进行操作|将工作表名称作为字符串传递

sheet = SpreadSheet.createFromFile(file).getSheet(0);



//获取行数和列count

int nColCount = sheet.getColumnCount();

int nRowCount = sheet.getRowCount();



System.out.println(Rows:+ nRowCount);

System.out.println(Cols:+ nColCount);

//遍历每个所选表格的一行

MutableCell cell = null;

for(int nRowIndex = 0; nRowIndex< nRowCount; nRowIndex ++)

{

//迭代每一列

int nColIndex = 0;

for(; nColIndex< nColCount; nColIndex ++)

{

cell = sheet.g etCellAt(nColIndex,nRowIndex);

System.out.print(cell.getValue()+);

}

系统。 out.println();

}



}

catch(IOException e)

{

e.printStackTrace();

}

}

public static void main(String [] args){

//创建.ods文件的文件对象

文件文件=新文件(D:\\Users\\ test。 ods);

OdsReader objODSReader = new OdsReader();

objODSReader.readODS(file);

}



我上面的代码在控制台上打印电子表格数据但我需要的是如果第14列中的数据不是空的话我需要在数据库中插入数据pty它应该显示该列中的空行号。任何人都可以帮助我,因为我是学习者和新人。



我尝试过:



i无法做到这一点

Below is my code which is used to read open office spread sheet data where i have 16 columns in it the problem is out of 16 columns i have 14 th column where the data cannot be empty in that 14 th column if any cell is empty i should show an error message by showing the row numbers of that column that these rows are empty please fill and if all the cells are filled in that column the data should get inserted into database how can i do this can any one help me outas i am new to this



public void readODS(File file)
{
Sheet sheet;
try
{
//Getting the 0th sheet for manipulation| pass sheet name as string
sheet = SpreadSheet.createFromFile(file).getSheet(0);

//Get row count and column count
int nColCount = sheet.getColumnCount();
int nRowCount = sheet.getRowCount();

System.out.println("Rows :"+nRowCount);
System.out.println("Cols :"+nColCount);
//Iterating through each row of the selected sheet
MutableCell cell = null;
for(int nRowIndex = 0; nRowIndex < nRowCount; nRowIndex++)
{
//Iterating through each column
int nColIndex = 0;
for( ;nColIndex < nColCount; nColIndex++)
{
cell = sheet.getCellAt(nColIndex, nRowIndex);
System.out.print(cell.getValue()+ " ");
}
System.out.println();
}

}
catch (IOException e)
{
e.printStackTrace();
}
}
public static void main(String[] args) {
//Creating File object of .ods file
File file = new File("D:\\Users\\test.ods");
OdsReader objODSReader = new OdsReader();
objODSReader.readODS(file);
}

My above code prints the spreadsheet data on the console but what i need is i need to insert the data in database if the data in 14th column is not empty if any cell is empty it should show row numbers which are empty in that column.can anyone help me out as i am learner and new to this

What I have tried:

i am unable to get how to do that

推荐答案

for( ;nColIndex < nColCount; nColIndex++)
{
    cell = sheet.getCellAt(nColIndex, nRowIndex);
    //
    // Check if this is column 14
    // and if the cell is empty
    //
    if (colIndex == 13 && cell.getValue == null)
    {
        System.out.print("Error message here");
    }
    System.out.print(cell.getValue()+ " ");
}


这篇关于在读取打开的办公室电子表格时识别列中的空白单元格并显示它们而不插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 11:36