XSSFWorkbook wbk = new XSSFWorkbook(file);
XSSFSheet sheets = wbk.getSheet("Sheet1");
Iterator row = sheets.iterator();
while (row.hasNext()){
Row rowItr = (Row) row.next();
Iterator cellItr = rowItr.cellIterator();
while (cellItr.hasNext()){
#SuppressWarnings("rawtypes")
Cell cell1 = (Cell) cellItr.next();
/* switch (cell1.getCellType()){
case Cell.CELL_TYPE_STRING:
data.add(cell1.getStringCellValue());
break;
case Cell.CELL_TYPE_NUMERIC:
data.add(cell1.getNumericCellValue());
break;
case Cell.CELL_TYPE_BOOLEAN:
data.add(cell1.getBooleanCellValue());/*
In the commented line I am getting an error displaying
" cast The method getCellType() is undefined for the type Table.Cell "
. Why I am getting this error and how to fix it.
Related
I have an UserForm where user will check the checkbox, which will be copied to the Excel sheet. When opening the UserForm, It will check the data from Excel sheet and while clicked on Apply button on UserForm, UserForm data will be placed in the Excel Sheet.
CheckBox Objects will be like -
UserFrom Name : Config
CheckBox Names : B1M101, B1M102, B1M103 (will be supplied dyanmically)
Here is my working, (which is not working) -
For i2 = 1 To 99
ModuleN = "B1M10"+i2
BeckDIE = "Config." + ModuleN
BeckDIV = "Config." + ModuleN
ExIntCellE = Sheets("Internal").Cells(RowStart + i2, EnableModify)
ExIntCellV = Sheets("Internal").Cells(RowStart + i2, ValueModify)
BeckDIE.Enabled = ExIntCellE.Value 'Getting Compile Error Here
BeckDIV.Value = ExIntCellV.Value 'Getting Compile Error Here
Next i2
So, i am trying to copy the values from Excel Sheet "Internal" to the CheckBoxs in the UserForm. But when i am executing this code, i am getting the Compiler Error : Invalid qualifier Error during the execution -
BeckDIE.Enabled = ExIntCellE.Value
BeckDIV.Value = ExIntCellV.Value
How can i assign the Excel Sheet Cell Value to the Dynamically created CheckBox ObjectName as string ?
I have tried to execute many forms like Application.Evaluate or Eval functions by only Executing the String Name as Object or Entire Name -
Application.Evaluate(BeckDIE).Enabled = False
Eval(BeckDIE).Enabled = False
Application.Evaluate(BeckDIE + ".Enabled") = False
Eval(BeckDIE + ".Enabled") = False
But, No luck. It's giving error.
As suggested by #PEH, Following Code has worked for me -
For i2 = 1 To 99
ModuleN = "B1M10"+i2
BeckDIE = ModuleN
BeckDIV = ModuleN
ExIntCellE = Sheets("Internal").Cells(RowStart + i2, EnableModify).Value
ExIntCellV = Sheets("Internal").Cells(RowStart + i2, ValueModify).Value
Config.Controls(BeckDIE).Enabled = ExIntCellE
Config.Controls(BeckDIV).Value = ExIntCellV
Next i2
I am pretty new to Selenium and learning through self study. Any help will be appreciable.
Currently I am using
String data = wb.getSheetAt(sheetnum).getRow(row).getCell(col).getStringCellValue();
It is working fine for String but not for numeric. I have a cell value of '500' and I want to fetch it. Please help.
Try out following code :
public void readfile(String filepath, String filename, String sheetname) throws IOException {
File file = new File(filepath+"\\"+filename);
FileInputStream fis = new FileInputStream(file);
// for creating .xlsx workbook
Workbook wb = new XSSFWorkbook(fis);
// for reading the sheet by its name
Sheet sh = wb.getSheet(sheetname);
// find the total rows in sheet
int rowcount = sh.getLastRowNum() - sh.getFirstRowNum();
// create a loop to create
for (int i = 0; i < rowcount + 1; i++) {
Row row = sh.getRow(i);
// create a loop to print cell values
for (int j = 0; j < row.getLastCellNum(); j++) {
Cell cell = row.getCell(j);
switch (cell.getCellType()) {
case Cell.CELL_TYPE_STRING:
System.out.print(row.getCell(j).getStringCellValue() + " ");
break;
case Cell.CELL_TYPE_NUMERIC:
System.out.print((int)row.getCell(j).getNumericCellValue() + " ");
break;
}
}
System.out.println();
}
}
Hope it will help you.
Double data = wb.getSheetAt(sheetnum).getRow(row).getCell(col).getNumericCellValue();
I know how to format cell values in EPPlus but only if the format applies to the whole value. How can I add formatting that only applies to part of the cell value?
for example...
Use the RichText collection to build it:
using (var pck = new ExcelPackage())
{
var wb = pck.Workbook;
var ws = wb.Worksheets.First();
var cell = ws.Cells["B2"];
cell.RichText.Add("This is some ");
cell.RichText.Add("formatting");
cell.RichText.Add(" withing a value");
cell.RichText[1].Color = Color.Red;
cell.RichText[1].Size = 14;
pck.Save();
}
Please see below code its working fine and searching for all excel files in given directory. But I am not able to understand this code
Doubt : NoOfFolders(Iterator1) is a dynamic array and when again function is called fnFolderStructure , NoOfFolders array is again created. But even values NoOfFolders(0) and NoOfFolders(1) changed but still when again its is called with previous values.
How it is able to retain values even after writing of NoOfFolders(Iterator1).
fnCheckFiles("C:\Temp\Sahil")
Function fnFolderStructure(sAddress)
i=0
Dim NoOfFolders()
Set objFSO1 = CreateObject("Scripting.FileSystemObject")
Set objFolder2 = objFSO1.GetFolder(sAddress)
Set FolderIn=objFolder2.SubFolders
Set FileIn=objFolder2.Files
' If FileIn.Count>0 Then
' fnCheckFiles(sAddress)
' End If
If FolderIn.Count>0 Then
y=FolderIn.Count
ReDim NoOfFolders(y-1)
For Each objSubfolder in FolderIn
NoOfFolders(i)= objSubfolder.Name
i=i+1
Next
For Iterator1 = 0 To y-1
sPath1=sAddress&"\"&NoOfFolders(Iterator1)
fnCheckFiles(sPath1)
Next
' Set colSubfolders = FolderIn.Subfolders
' Call fnFolderStructure(sPath1)
End If
End Function
Function fnCheckFiles(sAddress)
Set objFSO1 = CreateObject("Scripting.FileSystemObject")
Set objFolder4 = objFSO1.GetFolder(sAddress)
''sFileName=objFolder4.Name
For Each objFile In objFolder4.Files
sFileName=objFile.Name
if (InStr(1,sFileName,"xlsx",1)) then
msgbox objFile.Name
End IF
Next
if objFolder4.SubFolders.Count>0 then
fnFolderStructure(sAddress)
End if
End Function
How it is able to retain values even after writing of
NoOfFolders(Iterator1)
The array is not being written to by that statement. The array NoOfFolders is used in four places...
1) Declares the value as a dynamic array
Dim NoOfFolders()
2) Redimensions the variable to match the size of the number of folder names it will hold
ReDim NoOfFolders(y - 1)
3) Assigns the name of a folders to the corresponding position in the array. This is the only place where values are written to the array.
NoOfFolders(i) = objSubFolder.Name
4) Reads the name of a folder from the array to build a path of a sub-folder
sPath1 = sAddress & "\" & NoOfFolders(Iterator1)
====================================================================================================================*/
def getTagValue(def filepath, def tagName,log)
{
def tagValue = ""
try
{
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance()
DocumentBuilder docBuilder = docFactory.newDocumentBuilder()
Document doc = docBuilder.parse(filepath)
// Get the root element
Node company = doc.getFirstChild()
NodeList nodes = doc.getElementsByTagName(tagName)
//log.info "Nodes length :" +nodes.getLength()
Node node = nodes.item(0)
//log.info node.getTextContent()
tagValue = node.getTextContent()
if(tagValue == "")
{
tagValue = "tag not found"
}
}
catch(Exception e)
{
log.error e.message
tagValue = "tag not found"
}
return tagValue
}
==============================
def List readXpaths(def expectedExcelPath, def expectedExcelSheet, log, context)
{
Fillo.Connection con=getFilloConnection(expectedExcelPath,log)
String sQuery="Select * from "+expectedExcelSheet+" where TestCaseName='"+context.testCase.name+"'"
//log.info sQuery
Recordset rs=getRecordSet(con,sQuery,log)
List<String> colList=rs.getFieldNames()
colList.remove("TestCaseName")
colList.remove("DATA_SET")
colList.remove("RUN")
List<String> xpaths=new ArrayList<String>()
while(rs.next())
{
for(String str:colList)
{
if(rs.getField(str)!="")
{
xpaths.add(rs.getField(str))
}
}
}
return xpaths;
}
Workbook workbook = Workbook.getWorkbook(new File("C:\\Users\\Tsss-Pc1\\Desktop\\login.xls"));
Sheet sheet = workbook.getSheet(0);
String uname = sheet.getCell(0, 0).getContents();
d.findElement(By.id("inputEmail")).sendKeys(uname);
String pwd = sheet.getCell(1, 0).getContents();
d.findElement(By.id("inputPassword")).sendKeys(pwd);
d.findElement(By.xpath("//div[3]/div/button")).click();
This is my code for reading user name and password from login.xls, i want to append the results in the third column in same file.
WritableCell label = new Label(2,0, "pass");
WritableSheet sheet1 = null;
sheet1.addCell(label);
I tryed with this code, but it's not working for me..
can any one tell me, how to do this...
WritableWorkbook workbook = Workbook.createWorkbook(new File("d://output6.xls"));
WritableSheet sheet = workbook.createSheet("First Sheet", 0);
Label label = new Label(0, 0, "pass");
sheet.addCell(label);
workbook.write();
workbook.close();
}