Delete Column from spreadsheet using OpenXML - openxml

I was wanting to delete a column using openxml, I am able to clear the contents of the cell, but have been unable to find documentation to delete the column as to shift the other cells left when the column is deleted. How may I delete the column using openxml where it will shift the cells to the left?

I discovered that OpenXml has no way to delete a column on its own. Therefor to solve my problem I wrote a function that first removed the contents of the cells in the column I was deleting and then to set the cell reference of the columns that came behind the column I was deleting up a column.

You can iterate for each row and remove the cell you need
private void RemoveCell(int rowIndex, int colIndex)
{
SheetData sheetData = _worksheetPart.Worksheet.GetFirstChild<SheetData>(); // get the sheet
Row row = sheetData.Elements<Row>().FirstOrDefault(r => r.RowIndex == rowIndex);
if (row != null && row.Count() > colIndex)
row.RemoveChild(row.ElementAt(colIndex));
}

Related

Creating a For loop that iterates through all the numbers in a column of a table in Matlab

I am a new user of MatlabR2021b and I have a table where the last column (with name loadings) spans multiple sub-columns (all sub-columns were added under the same variable/column and are threated as one column). I wanto to create a For loop that goes through each separate loading column and iterates through them, prior to creating a tbl that I will input into a model. The sub-columns contain numbers with rows corresponding to the number of participants.
Previously, I had a similar analogy where the loop was iterating through the names of different regions of interest, whereas now the loop has to iterate through columns that have numbers in them. First, the numbers in the first sub-column, then in the second, and so on.
I am not sure whether I should split the last column with T1 = splitvars(T1, 'loadings') first or whether I am not indexing into the table correctly or performing the right transformations. I would appreciate any help.
roi.ic = T.loadings;
roinames = roi.ic(:,1);
roinames = [num2str(roinames)];
for iroi = 1:numel(roinames)
f_roiname = roinames{iroi};
tbl = T1;
tbl.(roinames) = T1.loadings(:,roiname);
**tbl.(roinames) = T1.loadings_rsfa(:,roiname)
Unable to use a value of type cell as an index.
Error in tabular/dotParenReference (line 120)
b = b(rowIndices,colIndices)**

How do I find the table name that my bookmark is in?

I have a word document with multiple tables. Within some of the tables, in row 2, column 1, I have multiple bookmarks that include text. I need to find if the bookmark is in a specific table. How do I know what table my bookmark is in? Or can I list the bookmarks within a table's cell. Either one will work.
I figured out my answer. I loop through the number of bookmarks within that table.
' returns the number of bookmarks in the table
ltable = ActiveDocument.Tables(i).Range.Bookmarks.Count
' place items in table
For j = 1 To ltable
On Error GoTo Skip2
sTemp = ActiveDocument.Tables(i).Range.Bookmarks(j).Name
sChgStr = ActiveDocument.Bookmarks(sTemp).Range.Text
If Len(sChgStr) > 0 Then
sc(1) = ItemNumber(sChgStr, 1)
sc(2) = RevisionLetter(sChgStr)
Call FillSummaryTable(sc())
End If
....

how to access one by on value of the stored procedure and calculate the average of them row wise

I executed a stored procedure in java which results into a table of 16 column and 3600 rows.Now I want to access 3 column of the retrieved table in row by row fashion and calculate the average of all column in row wise fashion.To do this,I need to access values of columns one by one .How to do it. My code for accessing column is
while (rs.next())
{
a1=rs.getDouble(7);
a2=rs.getDouble(8);
a3=rs.getDouble(10);
sum +=(a1+a2+a3);
}
return sum/3;
but through this,i think i'am getting a total average of all the columns .But i need average of column row by row i.e average of all three column of first row,then second row ...like this.
You are indeed adding all the values from 3 columns and doing row by row addition.
If you want row by row, then for each entry that you get from database you need to store the result in a list like below and return it where needed:
List<Double> averageList = new ArrayList<Double>();
while (rs.next())
{
a1=rs.getDouble(7);
a2=rs.getDouble(8);
a3=rs.getDouble(10);
averageList.add((a1+a2+a3)/3.0);
}
return averageList;

How to select a row in kendogrid after filtering

I have a kendogrid. What I do is first filter it, which works fine.
After having it filtered, I want to select a specific row. I am sure I have the row in the result of the filter.
Example:
data = id=a1, id=a2, id=a3, id=a4, id=a5, id=a6
filter result:
id=a2, id=a4, id=a6
I would like to select the row a4.
First of all loop through the Grid's data which is currently displayed (i.e.
var arrayOfModels = $('#GridName').data().kendoGrid.dataSource.view();
next add the k-state-selected class to the row you want to make it selected
$('#GridName tbody [data-uid='+model.uid+']').addClass('.k-state-selected')
where model is the record from the arrayOfModels above which you need

delete rows based on checkbox selection in slickgrid

i am taking help of this example: http://mleibman.github.com/SlickGrid/examples/example-checkbox-row-select.html and add a checkbox column to my grid and assign unique_id value of my record to the id of checkbox column i am getting checked columns number using grid.getSelectedRows();
it gives me a index number of row. how can i get id of this selected rows in slickgrid? please help me if anyone have any idea.
var selectedrows = grid.getSelectedRows();
for(i=0;i<len;i++){
var d = grid.getData().getItem(selectedrows[i]);
if(d != null && d != 'undefined'){
dataView.deleteItem(d.id);
grid.invalidate();
grid.updateRowCount();
grid.render();
}
}
It removes rows from grid. not from server side.