I want to get all check boxes in page checked.
How to select all check boxes and enable all ?
var chk = browser.checkboxes.where(x => x.id("test string"));
You can use this approach.
'
//Getting the count of the check boxes on the page.
int countOfCheckBox = browser.CheckBoxes.Count;
for (int i = 0; i < countOfCheckBox; i++)
{
browser.CheckBoxes[i].Checked = true;
}
'
Related
I export excel using Apache POI with drop down and many cell comments in it. When generating less cell comments, drop down's options appear for choosing when clicking drop down arrow, but when generating much cell comments, the drop down's options don't appear.
I do test with latest Apache POI version - 4.1.0.
HSSFWorkbook wb=new HSSFWorkbook();
HSSFSheet sheet=wb.createSheet("my sheet");
// create cell and add comments
int rowNum = 25;
int columnNum = 50;
HSSFPatriarch p=sheet.createDrawingPatriarch();
for (int i=0; i<rowNum; i++) {
HSSFRow row = sheet.createRow(i);
for (int j=0; j<columnNum; j++) {
HSSFCell cell = row.createCell(j);
cell.setCellValue(new HSSFRichTextString((i+1)+","+(j+1)));
if (i != 0 || j != 0) {
HSSFComment comment=p.createComment(new HSSFClientAnchor(0,0,0,0,(short)3,3,(short)5,6));
comment.setString(new HSSFRichTextString("comment for cell: " + (i+1) +","+(j+1)));
cell.setCellComment(comment);
}
}
}
// add drop down
String hiddenSheetName = "hiddenSheet";
HSSFSheet hiddenSheet = wb.createSheet(hiddenSheetName);
wb.setSheetHidden(wb.getSheetIndex(hiddenSheet), true);
HSSFRow hiddenRow = null;
HSSFCell hiddenCell = null;
String[] menuItems = {"Yes", "No"};
for (int i = 0; i < menuItems.length; i++)
{
hiddenRow = hiddenSheet.createRow(i);
hiddenCell = hiddenRow.createCell(0);
hiddenCell.setCellValue(menuItems[i]);
}
HSSFName namedCell = wb.createName();
String formulaId = "formulaId";
namedCell.setNameName(formulaId);
namedCell.setRefersToFormula(hiddenSheetName + "!A$1:A$" + menuItems.length);
HSSFDataValidationHelper dvHelper = new HSSFDataValidationHelper(sheet);
DataValidationConstraint dvConstraint = dvHelper.createFormulaListConstraint(formulaId);
CellRangeAddressList addressList = new CellRangeAddressList(0, 0, 0, 0);
HSSFDataValidation validation = (HSSFDataValidation)dvHelper.createValidation(dvConstraint, addressList);
sheet.addValidationData(validation);
FileOutputStream out = null;
try{
out=new FileOutputStream("exportExcelTest.xls");
wb.write(out);
out.close();
} catch (Exception e) {
}
From my test result, when commenting out cell comments generation part, drop down's options appear for choosing when clicking drop down arrow and when setting variable rowNum to 15, the drop down's options also appear. When setting variable rowNum to 25, then it will generate much more cell comments, then drop down's options don't appear. And if setting rowNum to be greater than 25, options also don't appear. So I infer this problem is related to number of comments generated. I am not sure if this is an Apache POI issue or there is anything I write incorrectly in code. Hope someone can help me to figure out this problem.
These numbers I give to rowNum are just for test, you can give any rowNum to try.
I think it has nothing to do with the comments and the number of comments.
By using new CellRangeAddressList(0, 0, 0, 0) you apply the validation to exactly one cell (A1).
By changing it to new CellRangeAddressList(0, rowNum - 1, 0, columnNum - 1) you apply the validation to all the cells that are created.
The second thing you should change is your formula. Instead of !A$1:A$ you should write !$A$1:$A$.
I am using Visual Studio 2010 and want to count number of lines in a C# textbox. I have tried Textbox.Lines.Count but it is not working as "Lines" is no more available in 2010.Is there any alternate way?
Try use
var count = Textbox.Lines.Length;
More detail here
Or try this:
string[] tmpArray = textBox1.Lines;
int count = tmpArray.Length;
int first = 0;
int last = 0;
count=0;`enter code here`
last = textBox.GetLastVisibleLineIndex();
count++;
while (first <= last)
{
String dummy = textBox.GetLineText(first);
if (dummy.Contains("\n") || dummy.Contains("\r") || dummy.Contains("\r\n"))
{
dummy = dummy.TrimEnd('\r', '\n');
count++;
}
first++;
}
I am generating a powerpoint presentation using apache POI - XSLF, on the fly when the user clicks a certain link on my website. I have a few tables with data on my presentation file and also an image (Line chart) generated using jfreechart. When I open the PPTX on my machine it seems to work fine. However when I open the file on another machine that has the powerpoint 2013, I get the following error.
"powerpoint found a problem with content powerpoint can attempt to repair the presentation".
I want to get rid of this error. I read on the internet that the solution is to "UNBLOCK" the powerpoint, which can be done through the properties section of the file. I am wondering if there's something I can do programmatically to suppress this errors for my users. This error message is annoying at the least.
My last thread on this was deleted - https://stackoverflow.com/questions/41163148/how-to-unblock-pptx-using-apache-poi
Hence re-creating this thread here again. A bug is also entered in bugzilla for apache POI. Bug Id - 60633 (https://bz.apache.org/bugzilla/show_bug.cgi?id=60633).
XSLFTableCell cell
XSLFTextParagraph p
XSLFTextRun line
XSLFTable tbl = slide.createTable();
tbl.setAnchor(new Rectangle(X, Y, WIDTH, HEIGHT));
XSLFTableRow headerRow = tbl.addRow();
headerRow.setHeight(45);
//Loop through the data collection and populate rows and columns.
for(int i = 0; i < numberOfCols; i++) {
XSLFTableCell th = headerRow.addCell();
p = th.addNewTextParagraph();
p.setTextAlign(TextAlign.CENTER);
line = p.addNewTextRun();.....}
for (int item=0; item < 8; item++)
{
XSLFTableRow itemRow = tbl.addRow();.....}
//finally write the file
File pptFile = File.createTempFile("fileName", ".ppt")
FileOutputStream out = new FileOutputStream(pptFile)
ppt.write(out)
out.close()
If one provides code along with a bug report, then this code must be complete and verifiable. Your code is not complete and verifiable. And if i do completing it, then it works without problems.
import java.io.FileOutputStream;
import org.apache.poi.xslf.usermodel.*;
import org.apache.poi.sl.usermodel.TextParagraph.TextAlign;
import org.apache.poi.sl.usermodel.TableCell.BorderEdge;
import org.apache.poi.sl.usermodel.TextParagraph.TextAlign;
import java.awt.Rectangle;
import java.awt.Point;
import java.awt.Color;
public class CreatePPTX {
public static void main(String[] args) throws Exception {
XMLSlideShow ppt = new XMLSlideShow();
XSLFSlide slide = ppt.createSlide();
XSLFTableCell cell;
XSLFTextParagraph p;
XSLFTextRun line;
XSLFTable tbl = slide.createTable();
tbl.setAnchor(new Rectangle(new Point(100, 100)));
XSLFTableRow headerRow = tbl.addRow();
headerRow.setHeight(45);
for(int i = 0; i < 5; i++) {
XSLFTableCell th = headerRow.addCell();
p = th.addNewTextParagraph();
p.setTextAlign(TextAlign.CENTER);
line = p.addNewTextRun();
line.setText("Header " + i);
th.setBorderWidth(BorderEdge.bottom, 2.0);
th.setBorderColor(BorderEdge.bottom, Color.black);
}
for (int item=0; item < 8; item++) {
XSLFTableRow itemRow = tbl.addRow();
for (int i = 0; i < 5; i++) {
XSLFTableCell td = itemRow.addCell();
p = td.addNewTextParagraph();
p.setTextAlign(TextAlign.CENTER);
line = p.addNewTextRun();
line.setText("Cell " + item + ":" +i);
}
}
FileOutputStream out = new FileOutputStream("fileName.pptx");
ppt.write(out);
out.close();
}
}
So your problem is not reproducible using the code you have provided.
But one thing can lead to your issue. If cells shall be empty in the table, then do not create empty runs but let the cell totally empty.
Example with the above code, if cell 1:1 shall be empty, then do not:
...
for (int item=0; item < 8; item++) {
XSLFTableRow itemRow = tbl.addRow();
for (int i = 0; i < 5; i++) {
XSLFTableCell td = itemRow.addCell();
p = td.addNewTextParagraph();
p.setTextAlign(TextAlign.CENTER);
line = p.addNewTextRun();
if (!(item==1 && i==1)) {
line.setText("Cell " + item + ":" +i);
}
}
}
...
This leads to the error.
Instead do:
...
for (int item=0; item < 8; item++) {
XSLFTableRow itemRow = tbl.addRow();
for (int i = 0; i < 5; i++) {
XSLFTableCell td = itemRow.addCell();
p = td.addNewTextParagraph();
p.setTextAlign(TextAlign.CENTER);
if (!(item==1 && i==1)) {
line = p.addNewTextRun();
line.setText("Cell " + item + ":" +i);
}
}
}
...
I could not find a way to make a RTL paragraph in Docx using XWPFDocument (Apache POI) in my Java program. Here's my code that generates the XWPFDocument.
XWPFParagraph title = document.createParagraph();
title.setAlignment(ParagraphAlignment.CENTER);
title.setVerticalAlignment(TextAlignment.CENTER);
title.setWordWrap(true);
XWPFRun titleRun = title.createRun();
titleRun.setText(reportDesign.getName());
XWPFTable s = document.createTable(resultList.size()+1, columnList.size());
// declare a row object reference
XWPFTableRow r = s.getRow(0);
// declare a cell object reference
XWPFTableCell c = null;
// create columnList.size() cells (0-(columnList.size()-1))
for (int cellnum = 0; cellnum < columnList.size(); cellnum++) {
c = r.getCell(cellnum);
c.setColor("c9c9c9");
c.setVerticalAlignment(XWPFVertAlign.CENTER);
c.setText(columnList.get(cellnum).getColumnHeader());
}
// create a sheet with resultList.size() rows (1-resultList.size())
for (int rownum = 0; rownum < resultList.size(); rownum++) {
// create a row
r = s.getRow(rownum+1);
// create columnList.size() cells (0-(columnList.size()-1))
for (int cellnum = 0; cellnum < columnList.size(); cellnum++) {
c = r.getCell(cellnum);
Object value = resultList.get(rownum).get(columnList.get(cellnum).getColumnKey());
if (value != null) {
c.setText(value.toString());
} else {
c.setText("");
}
}
}
Would you please help me? Is there a logical way to extend POI (or similar solution) for gaining this feature?
A workaround that I found till now is using a template document.
Using this method, you make an empty document that "Normal" style in it, is configured to be RTL. This way, everything in your document will be RTL.
XWPFDocument document = new XWPFDocument(AbstractWordView.class.getClassLoader().getResourceAsStream("empty.docx"));
i need assistance with this code. not sure how to write a code to disable/enable the button based on a tag.
i tried to use "[levelMenu setIsEnabled:false];" but all the buttons are disabled.
//in my init method
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:#"texture.plist"];
CCSpriteBatchNode *colorSprites = [CCSpriteBatchNode batchNodeWithFile:#"texture.png"];
[self addChild:colorSprites];
CCMenu *myMenu = [CCMenu menuWithItems:nil];
int rows = 2;
int cols = 4;
static int padding=20;
for(int count=0; count < (rows*cols); count++) {
int index1 = count +1;
NSString *spritefiles1 = [NSString stringWithFormat:#"sprite%d.png", index1];
random1 = [CCSprite spriteWithSpriteFrameName:spritefiles1];
CCMenuItemSprite *levelMenu = [CCMenuItemSprite itemFromNormalSprite:random1 selectedSprite:[CCSprite spriteWithFile:#"Iconselected.png"] disabledSprite:[CCSprite spriteWithFile:#"Iconlocked.png"] target:self selector:#selector(levelSelected:)];
int yOffset = padding+(int)(random1.contentSize.width/2-((random1.contentSize.width+padding)*(count/rows))); // or /cols to fill cols first
int xOffset = padding+(int)(random1.contentSize.width/2+((random1.contentSize.width+padding)*(count%rows))); // or %cols to fill cols first
levelMenu.position = ccp(xOffset, yOffset);
levelMenu.tag = count+1;
myMenu.position =ccp(0,300);
[myMenu addChild:levelMenu];
//testing to disable the button
// [levelMenu setIsEnabled:false];
}
-(void) levelSelected:(CCMenuItemSprite*) sender {
int level = sender.tag;
NSLog(#"test button number %d",level);
}
You may want to read this post
In Cocos2d, with buttons on multiple layers, how can I control which button to react to user's touch?
I tried, it worked for me
[_fireButton setIsEnabled:NO];