i struggling to remove a table from a XSSFWorkbook.
I already tried to remove all columns from a table, which leads to an IllegalArgumentException: Table must have at least one column expection.
The Apache POI exposes only methods to remove individual columns, which leads to the described exception.
An another thread references a possible solution
for (XSSFTable table : sheet.getTables()) {
workbook.removePartRelation(table, true);
}
by removing relations from a workbook. The current API doesn't expose a removePartRelation, though. In addition, the possible replacement removeRelation is protected.
Is there another possibility to remove tables from a XSSFWorkbook?
Related
I have one query which I then reference four more times in order to load the exact same table 5 times within a workbook. Is there a way of just loading the one query to 5 different locations within the workbook without having to create 4 more queries which just reference the initial query? Currently this is slowing the performance as each 'Refresh All' results in the 5 queries being all refreshed
There is a way in Power Query to have the one query then you can reference or duplicate it.
Duplicate is a copy of the data with all the same steps. Reference will only have the one step, which is get data from the referenced data set. In this case you will need to reference it.
Right click on the dataset and select the reference option
Jon interpretation of "reference" is wrong. Using "reference" will still re-run the referenced query. "reference" only makes the overall code more succinct and dynamically pegged to the referenced query (in case if you edit the referenced query). It does not reduce the querying steps, and hence will never achieve your desirable performance.
I have a complex workbook full of formulas linking back to a set of tabs at the beginning which contain the source data.
Currently that data is stored as a static set of data. I want to replace it with a dynamic external connection. Problem is, when I load up the table it "helpfully" shunts the existing static data to the side, and all the formulas in the workbook "helpfully" update to reflect that- so they point to the old data in the new cells, not my new table!
Is there any way to either
A) overwrite the cells rather than inserting extra extra columns
B) Long shot- temporarily Excel updating formulas?
I think that this question is similar to mine, but has no useful advice for my situation - I don't want to and probably can't manually update every formula range.
Thanks.
After some experimenting it turns out the inserting of extra columns only takes place if data is present in the cells you are going to overwrite.
So deleting the data (NOT the cells) and then loading the query to the now clean area will work fine- formulae in the rest of the workbook will continue to link to the table.
I have an Excel 2010 workbook with two SQL queries each returning data to a separate worksheet as a named table. They return the same db fields, but one is constrained on the values of one of the fields. I have additional columns using formulas to transform these field data, and these are also identical between worksheets.
Upon refresh, Excel autofills the formulae per the conventions of a named table. One of the sheets/tables--call it Table 1-- autofills with native references (e.g., for a field/column named variable, the corresponding formula uses [#[variable]] as its reference. However, the other table--call it Table 2--autofills with references to Table 1, i.e., 'Table 1'[#[variable]].
I have searched and replaced these several times, and rewritten the formulae, but each time I refresh the data query these references pop up. I searched to replace Table 1 with Table 2, as it occurred to me this may be a namespace collision and Excel just takes the first-created table as canon. This, though, doesn't fix the issue, nor did changing the column names to create a non-colliding namespace.
The only other thing I can think is that I'd copied the formulas from Table 1 and even though I removed the table name perhaps Excel has held onto the reference. Is there a table cache or such that Excel references to keep pulling these? Should I create a new query and new table and manually create the formulae, or would that run into the same issue?
[Entering this as an answer so it's not shown as an outstanding question.]
Creating the relevant tables from scratch results in no such namespace collision nor any wonkiness thus far, as we'd expect. I realized that I'd left something out of my initial question: I had copied, in whole or part (likely whole), the tab containing Table 1 to create Table 2. Even editing the resulting new SQL query and the formulae on Table 2, it seems Excel--in its effort to help--recalls several components of the table and does not update this cached information.
I have an excel file and I want to import the excel file basing on the existing database table using entity framework. Right now I firstly convert the excel sheet to a DataTable and have a loop to loop through each row of the DataTable. Each row has an id field and if the id exists in the database table I need to update it otherwise I need to insert this row to the database table. I want to use entity framework to wrap my loop into one transaction for roll back purpose in case of error. But I run into a scenario of two rows with the same id but different values. The first row is checked and added my entity collection, but the second row might be mistakenly updated the firstly added row because the firstly is not actually added due to the delayed context.SaveChanges() called after the loop. How can I update the previously added row in the entity collection without repeatedly calling context.SaveChanges() inside my loop? Thanks.
I don't think I have done it over the past decade or so, but I have used Microsoft Word's Mail Merge to create the SQL statement that I needed (SELECT, INSERT and UPDATE) for each line in an Excel sheet. Once I got the long SQL statement in text I simply copy-paste it into the console and the statement was executed and the job was done. I am confident that there are better ways of doing this but it worked at the time with limited knowledge but a need. This answer is probably in the category "don't try this at work, but it is fine to do it at home if it does the job".
i have a QTableView. I am Querying data from database using QtSql.QSqlQuery.
SQL = 'SELECT * FROM table1'
Query = QtSql.QSqlQuery(database)
Query.prepare(SQL)
Query.exec_()
model = QtSql.QSqlTableModel()
model.setTable('Table')
model.setQuery(Query)
proxy = QtGui.QSortFilterProxyModel()
proxy.setSourceModel(model)
QTableView.setModel(proxy)
Everything is working file the Query result is show in the QTableView.
My Issues is when i change the SQL statement which results Query to return 0 records, I need to clear the data and the cells in the QTableView
I tried using QTableView.clear() its clearing the data in the cells leaving behind empty rows and columns. How can i clear QTAbleView completly
In c++ there is a reset function for QAbstractItemView.
you could say
yourTableView.reset();
My research on clearing data worked.
I Used proxy.deleteLater()
Hope someone could get benefited who comes across the same situation
What I prefer using in this situation is a bit of a workaround, due to the limitations of QTableView
In my own personal program, I decided instead to hide the rows and columns of the QTableView, making it to appear as though it is set to default and blank. The reason for this is, if you delete the widget, you need to replace it and this also resets all of the object's properties. This could theoretically force you to re-assign all the properties of your QTableView every time you need it to just display as blank or cleared. Instead of deleting the widget, this proposed option can be done with just two simple loops and when you refresh your table and want to display the values again, just two simple loops again, gets the job done.
There are multiple ways to populate a QTableView, but whichever you use, you just need to iterate through the rows and columns of your table. Below is the method I use, based on a class that inherits from QtCore.QAbstractTableModel so that when I call dataFrame it returns a pandas dataframe of the QTableView data.
If you need to hide the table:
for _row in range(len(yourQTableView.model().dataFrame.index)):
yourQTableView.hideRow(_row)
for _col, col_name in enumerate(yourQTableView.model().dataFrame.columns):
yourQTableView.hideColumn(_col)
If you need to show the table:
for _row in range(len(yourQTableView.model().dataFrame.index)):
yourQTableView.showRow(_row)
for _col, col_name in enumerate(yourQTableView.model().dataFrame.columns):
yourQTableView.showColumn(_col)
To me, this is the easiest method and gets me the result I want. I can't think of a reason why this method wouldn't be preferred over deleting the widget altogether.
self.table_view.model().setRowCount(0)