How to get column and row count for a table in codede ui? - coded-ui-tests

I want to get row and colun numbers for a table but can not do it.
here is my table
WinTable uIG1Table = this.UIProMANAGEWindow.UIMachineListWindow.UIG1Window.UIG1Table;
First I used methods I have seen in this link but it did not work
http://executeautomation.com/blog/storetableinlist/
int rowCount = uIG1Table.RowCount;
int colCount = uIG1Table.ColumnCount;
I searched for WinTable API and I tried to use API methods. Since there is no columng structures, I used ColumnHeaders for column counting , both row and column brings me 0. Whata should I do ?
int rowCount = uIG1Table.Rows.Count;
int colCount = uIG1Table.ColumnHeaders.Count;
MessageBox.Show(rowCount.ToString());
MessageBox.Show(colCount.ToString());

Try searching all rows on the window using following code example:
internal UITestControlCollection GetGridRows()
{
var winSearchResults = FindWindowSearchResults();// this can be any WinWindow object
WinRow gridRows = new WinRow(winSearchResults);
gridRows.SearchProperties.Add(WinRow.PropertyNames.Name, "Row ", PropertyExpressionOperator.Contains);// in case of my AUT, the rows name property had "Row " at start
gridRows.SearchConfigurations.Add(SearchConfiguration.AlwaysSearch);
return gridRows.FindMatchingControls();
}
Once you have a row object, you can get cell count through cells property as below:
rowFromGrid.Cells

Related

export hashsmap to xlsx using nested for each loop

I have below loop trying to printout keys and values stored in a hashmap
// Create the first row corresponding to the header
Row header = Sheet.createRow(0);
int headerIndex = 0;
for (Map.Entry<String, List<String>> entry : resultsToPrint.entrySet()) {
String key = entry.getKey();
header.createCell(headerIndex).setCellValue(key);
int rowIndex = 1;
for (String value : entry.getValue()) {
// Creating row
Row row = Sheet.createRow(rowIndex);
// create cell
row.createCell(headerIndex).setCellValue(value);
rowIndex++;
}
headerIndex++;
}
the results I am getting looks like this:
This is what gets printed
what I need this loop to do, is to populate the values of the second column as well and if I add a third column, it needs to populate the values for the third column etc.
Please assist

match single cell value with column of values for every match return those rows Google-apps-script

I have a spreadsheet with 2 tabbed sheets. I am trying to run a macro so that when the user inputs a name in B2 of the 2nd sheet, it is matched with every instance of that name in the 1st sheet, column B. I then need to copy all of the data that appears in the matched cell's rows and have that pasted in the 2nd sheet starting with cell B3.
I have limited experience with VBA, but none with JS/Google-apps-script. Any help with how to write this would be greatly appreciated! Here is my first shot:
function onSearch() {
// raw data sheet
var original = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Form Responses 2");
// search for student sheet
var filtered = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Student Progress Search");
// retrieving the values in the raw data array of names
var searchColumn = 2;
var lr = original.getLastRow();
var searchRange = original.getRange(2,searchColumn, lr, 1).getValues();
// retrieving the name submitted on search
var inputName = filtered.getRange(2, 2).getValue();
// loop through all the names in the raw data and identify any matches to the search name
for (var i = 0; i < lr; i++){
var dataValue = searchRange[i];
var r = dataValue.getRow();
var line = [[r]];
var paste = filtered.getRange(3, 3);
// if the data is a match, return the value of that cell in the searched sheet
if (dataValue == inputName){ return paste.setValues(line);
}
}
}
Not sure if the built-in QUERY function would work for you. This here does exactly what you are looking for:
=QUERY(Sheet1!B:B,"select B where LOWER(B) like LOWER('%" &B2& "%')")
For example, if a user enters 'joe', the function will match any entry containing 'joe', regardless of case.

How can I provide a calculated value that is based on two other values in an Aspose.Cells PivotTable?

I am adding data fields to a PivotTable like so:
int TOTALQTY_COLUMN = 4;
int TOTALPRICE_COLUMN = 5;
. . .
pivotTable.AddFieldToArea(Aspose.Cells.Pivot.PivotFieldType.Data, TOTALQTY_COLUMN);
pivotTable.AddFieldToArea(Aspose.Cells.Pivot.PivotFieldType.Data, TOTALPRICE_COLUMN);
Or, providing more context:
Aspose.Cells.Pivot.PivotTableCollection pivotTables = pivotTableSheet.PivotTables;
int colcount = COLUMNS_IN_DATA_SHEET;
string lastColAsStr = ReportRunnerConstsAndUtils.GetExcelColumnName(colcount);
int rowcount = sourceDataSheet.Cells.Rows.Count;
string sourceDataArg = string.Format("sourceDataSheet!A1:{0}{1}", lastColAsStr, rowcount);
int index = pivotTableSheet.PivotTables.Add(sourceDataArg, "A7", "PivotTableSheet");
Aspose.Cells.Pivot.PivotTable pivotTable = pivotTables[index];
pivotTable.AddFieldToArea(Aspose.Cells.Pivot.PivotFieldType.Row, DESCRIPTION_COLUMN);
pivotTable.AddFieldToArea(Aspose.Cells.Pivot.PivotFieldType.Column, MONTHYR_COLUMN);
pivotTable.AddFieldToArea(Aspose.Cells.Pivot.PivotFieldType.Data, TOTALQTY_COLUMN);
pivotTable.AddFieldToArea(Aspose.Cells.Pivot.PivotFieldType.Data, TOTALPRICE_COLUMN);
I need another data field that is based on the values supplied to those two data fields (from the source data's TOTALQTY_COLUMN and TOTALPRICE_COLUMN columns), specifically TotalPrice divided by Total Qty.
Is this possible? If so, how can I do this?
I could create another column for the source data sheet that would contain this value and just reference it, but if I can avoid doing that by use of some calculation "trickery" it would be preferable.
I solved this by adding an extra column to my source data sheet, populating that by making the calculation described above (TotalPrice / TotalQty):
decimal avgPrice = 0.0M;
if ((TotalPrice > 0.0M) && (Quantity > 0))
{
avgPrice = TotalPrice/Quantity;
}
cell = sourceDataSheet.Cells[_lastRowAddedPivotTableData, 10];
cell.PutValue(Math.Round(avgPrice, 2));
...and then referencing that new data source column accordingly:
pivotTable.AddFieldToArea(Aspose.Cells.Pivot.PivotFieldType.Data, AVGPRICE_COLUMN);

DataTables - How do I get/set the value of a cell in a row?

I´m iterating through the rows of my DataTable with the example I found here in documentation but I want to get the data of the second column, analyze that value and then set my processed value on that cell.
tablaProgDetalle.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
// I suppose here goes the processing and the setting of the cells values.
});
SOLUTION
You can use row().data() inside the anonymous function to get and set row's data. Please note that variable this in inside the anonymous function refers to row being iterated.
var table = $('#example').DataTable();
table.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
var data = this.data();
data[0] = '* ' + data[0];
this.data(data);
});
DEMO
See this jsFiddle for code and demonstration.
You can use rowID to do this; we can set rowID in rowCreated: callback of Datatable, or manually while inserting rows upon table creation. Here I am incrementing 3rd column value upon some event in my project.
//DOM only addition
var rowID = your rowID goes here;
var cols = Table.row(rowID).data();
var count = parseInt(cols[2]);
count = count + 1
cols[2] = count.toString();
Table.row(rowID).data(cols);

openxml - inserting a row, moving others

I am using openxml to create an excel report. The openxml operates on a template excel file using named ranges.
The client requires a totals row at the end of the list of rows. Sounds like a reasonable request!!
However, the data table I'm returning from the db can contain any number of rows. Using template rows and 'InsertBeforeSelf', my totals row is getting overridden.
My question is, using openxml, how can I insert rows into the spreadsheet, causing the totals row to be be moved down each time a row is inserted?
Regards ...
Assuming you're using the SDK 2.0, I did something similiar by using this function:
private static Row CreateRow(Row refRow, SheetData sheetData)
{
uint rowIndex = refRow.RowIndex.Value;
uint newRowIndex;
var newRow = (Row)refRow.Clone();
/*IEnumerable<Row> rows = sheetData.Descendants<Row>().Where(r => r.RowIndex.Value >= rowIndex);
foreach (Row row in rows)
{
newRowIndex = System.Convert.ToUInt32(row.RowIndex.Value + 1);
foreach (Cell cell in row.Elements<Cell>())
{
string cellReference = cell.CellReference.Value;
cell.CellReference = new StringValue(cellReference.Replace(row.RowIndex.Value.ToString(), newRowIndex.ToString()));
}
row.RowIndex = new UInt32Value(newRowIndex);
}*/
sheetData.InsertBefore(newRow, refRow);
return newRow;
}
I'm not sure how you were doing it with InsertBeforeSelf before, so maybe this isn't much of an improvement, but this has worked for me. I was thinking you could just use your totals row as the reference row. (The commented out part is for if you had rows after your reference row that you wanted to maintain. I made some modifications, but it mostly comes from this thread: http://social.msdn.microsoft.com/Forums/en-US/oxmlsdk/thread/65c9ca1c-25d4-482d-8eb3-91a3512bb0ac)
Since it returns the new row, you can use that object then to edit the cell values with the data from the database. I hope this is at least somewhat helpful to anyone trying to do this...
[Can someone with more points please put this text as a comment for the M_R_H's Answer.]
The solution that M_R_H gave helped me, but introduces a new bug to the problem. If you use the given CreateRow method as-is, if any of the rows being moved/re-referenced have formulas the CalcChain.xml (in the package) will be broken.
I added the following code to the proposed CreateRow solution. It still doesn't fix the problem, because, I think this code is only fixing the currently-being-copied row reference:
if (cell.CellFormula != null) {
string cellFormula = cell.CellFormula.Text;
cell.CellFormula = new CellFormula(cellFormula.Replace(row.RowIndex.Value.ToString(), newRowIndex.ToString()));
}
What is the proper way to fix/update CalcChain.xml?
PS: SheetData can be gotten from your worksheet as:
worksheet.GetFirstChild<SheetData>();
You have to loop all rows and cells under the inserted row,change its rowindex and cellreference. I guess OpenXml not so smart that help you change index automatically.
static void InsertRow(string sheetName, WorkbookPart wbPart, uint rowIndex)
{
Sheet sheet = wbPart.Workbook.Descendants<Sheet>().Where((s) => s.Name == sheetName).FirstOrDefault();
if (sheet != null)
{
Worksheet ws = ((WorksheetPart)(wbPart.GetPartById(sheet.Id))).Worksheet;
SheetData sheetData = ws.WorksheetPart.Worksheet.GetFirstChild<SheetData>();
Row refRow = GetRow(sheetData, rowIndex);
++rowIndex;
Cell cell1 = new Cell() { CellReference = "A" + rowIndex };
CellValue cellValue1 = new CellValue();
cellValue1.Text = "";
cell1.Append(cellValue1);
Row newRow = new Row()
{
RowIndex = rowIndex
};
newRow.Append(cell1);
for (int i = (int)rowIndex; i <= sheetData.Elements<Row>().Count(); i++)
{
var row = sheetData.Elements<Row>().Where(r => r.RowIndex.Value == i).FirstOrDefault();
row.RowIndex++;
foreach (Cell c in row.Elements<Cell>())
{
string refer = c.CellReference.Value;
int num = Convert.ToInt32(Regex.Replace(refer, #"[^\d]*", ""));
num++;
string letters = Regex.Replace(refer, #"[^A-Z]*", "");
c.CellReference.Value = letters + num;
}
}
sheetData.InsertAfter(newRow, refRow);
//ws.Save();
}
}
static Row GetRow(SheetData wsData, UInt32 rowIndex)
{
var row = wsData.Elements<Row>().
Where(r => r.RowIndex.Value == rowIndex).FirstOrDefault();
if (row == null)
{
row = new Row();
row.RowIndex = rowIndex;
wsData.Append(row);
}
return row;
}
Above solution got from:How to insert the row in exisiting template in open xml. There is a clear explanation might help you a lot.

Resources