SXSSFSheet autoSizeColumn error on apache poi 4.1.2 - spring

My project using Spring Boot. I try to export data to excel file with org.apache.poi 4.1.2 , i use method autoSizeColumn to auto size column
headerRow.forEach(item -> {
sheet.autoSizeColumn(item.getColumnIndex());
});
but i get the error
java.lang.IllegalStateException: Could not auto-size column. Make sure the column was tracked prior to auto-sizing the column.
at org.apache.poi.xssf.streaming.SXSSFSheet.autoSizeColumn(SXSSFSheet.java:1591)
at org.apache.poi.xssf.streaming.SXSSFSheet.autoSizeColumn(SXSSFSheet.java:1545)
how to fix this error

I have fixed this issue following this link SXSSFSheet.autoSizeColumn is throwing IllegalStateException
i resolve this issue by using the method public void trackAllColumnsForAutoSizing() of class SXSSFSheet
public void trackAllColumnsForAutoSizing()
Tracks all columns in the sheet for auto-sizing. If this is called,
individual columns do not need to be tracked. Because determining the
best-fit width for a cell is expensive, this may affect the
performance.
Since:
3.14beta1

I have fixed the above issue with the following, do this only after you are done rendering everything on to the sheet
if you have list for columns then the following will work fine.
// autoSizing of the columns
for (int i = 0; i < columns.size(); i++) {
workbookSheet.trackAllColumnsForAutoSizing();
workbookSheet.autoSizeColumn(i);
}
For your case the below will work.
headerRow.forEach(item -> {
sheet.trackAllColumnsForAutoSizing();
sheet.autoSizeColumn(item.getColumnIndex());
});

Related

HowTo empty a Vaadin 8.3.0 Chart?

i tried to empty a Vaadin 8 chart. I tried to overwrite it with an empty DataSeries. What am I doing wrong?
if i use:
DataSeries emtpySeries = new DataSeries("");
getUI().access(() -> junkPerMachineChart.setData(emtpySeries));
i get no error, but the chart is still there.
inspired by https://vaadin.com/forum/thread/4550466/vaadin-chart-how-to-remove-all-dataseriesitem-from-a-series
i found a solution how i could empty my chart named junkPerMachineChart.
private void emptyJunkPerMachineChart(){
List<Series> s = new ArrayList<Series>();
junkPerMachineChart.getConfiguration().setSeries(s);
junkPerMachineChart.drawChart();
}

Is paging broken with spring data solr when using group fields?

I currently use the spring data solr library and implement its repository interfaces, I'm trying to add functionality to one of my custom queries that uses a Solr template with a SimpleQuery. it currently uses paging which appears to be working well, however, I want to use a Group field so sibling products are only counted once, at their first occurrence. I have set the group field on the query and it works well, however, it still seems to be using the un-grouped number of documents when constructing the page attributes.
is there a known work around for this?
the query syntax provides the following parameter for this purpose, but it would seem that Spring Data Solr isn’t taking advantage of it. &group.ngroups=true should return the number of groups in the result and thus give a correct page numbering.
any other info would be appreciated.
There are actually two ways to add this parameter.
Queries are converted to the solr format using QueryParsers, so it would be possible to register a modified one.
QueryParser modifiedParser = new DefaultQueryParser() {
#Override
protected void appendGroupByFields(SolrQuery solrQuery, List<Field> fields) {
super.appendGroupByFields(solrQuery, fields);
solrQuery.set(GroupParams.GROUP_TOTAL_COUNT, true);
}
};
solrTemplate.registerQueryParser(Query.class, modifiedParser);
Using a SolrCallback would be a less intrusive option:
final Query query = //...whatever query you have.
List<DomainType> result = solrTemplate.execute(new SolrCallback<List<DomainType>>() {
#Override
public List<DomainType> doInSolr(SolrServer solrServer) throws SolrServerException, IOException {
SolrQuery solrQuery = new QueryParsers().getForClass(query.getClass()).constructSolrQuery(query);
//add missing params
solrQuery.set(GroupParams.GROUP_TOTAL_COUNT, true);
return solrTemplate.convertQueryResponseToBeans(solrServer.query(solrQuery), DomainType.class);
}
});
Please feel free to open an issue.

Selection of a property in a compartment shape

I have a problem with selecting a property on a compartmentshape of a dsl. What I want to do is:
I have a DSL with one compartmentshape which has many properties in one compartment. Each of this properties has a textfield which is used for saving c# code. I compile this code and add the error tasks to the error list. I added an event handler for the navigate event of the error task. Inside this handler, i would like to select the property of the compartmentshape which is responsible for the error. I tried many things, but didn't succeeded. This is my current selection logic:
public void Select(Rule rule)
{
Library.Field ruleField = rule.Field as Library.Field;
var ruleFieldPresentation = PresentationViewsSubject.GetPresentation(ruleField as ModelElement).FirstOrDefault() as ShapeElement;
VSDiagramView activeDiagramView = Diagram.ActiveDiagramView as VSDiagramView;
if (activeDiagramView != null)
{
var docView = activeDiagramView.DocView;
activeDiagramView.Selection.Clear();
docView.CurrentDiagram.ActiveDiagramView.Selection.Set(new DiagramItem(ruleFieldPresentation));
}
}
The problem seems that an property of the compartmentshape doesn't have a presentationview, because I'm not able to get it.
I would be glad and very grateful if someone can helpe me with this problem.
Thank you
Regards Manuel
I wanted to open an error from the error list. There is a better solution than using the navigation event on an error. The better solution is to add a validation rule to the domain class and add the error with the context to the error list. Than the navigation to the property works out of the box.
context.LogError(errorDescription, "GAIN001RuleCompilationError", Field);

ListChangeListener, JavaFX

I have a question related to filters on a ObservableList. The code that i have works fine, but i think is too slow. This is beacause i load like 40,000 orders at the beginning of the app, after that the app keeps receiving orders, but for now i only have the problem in the initial load. My main problem is that the copy of my original collection of orders is considerably slower, why? because the code that i have in the changeListener i think that could be better.. but i haven't found a solution yet. Well here's an example of my code.
public MainController()
{
filteredData.addAll(Repository.masterObservableList);
Repository.masterObservableList.addListener(new ListChangeListener<OrderVo>()
{
#Override
public void onChanged(ListChangeListener.Change<? extends OrderVo> change)
{
filteredData.clear();
for (OrderVo o : Repository.masterObservableList)
filteredData.add(o);
}
});
}
}
I'll explain the code a little bit. the "Repository" is a singleton, the masterObservableList is a ObservableList and as the name says.. is the "master" or the original. The filteredData is also a ObservableList but is only declared in the controller of my fxml (MainController) and works as the copy of the master collection. Every time that my master collection recieve a change (update or new order) the filteredData should apply that change.. but im doing a for each iteration and this is problem, because it works but, too slow. Why im saying that is slow? Because in the beginning i was using the master collection as the data provider of a TableView that shows the orders and it worked fast and clean. After that i wanted to add filters to the table and thats when i began to do a research and found the filtered data and another methods.. i keeped this method (is a larger code, but the main problem is here).. and it works.. but the time that took to load the orders in the beginning is like 1:30 mins more than before.. So guys, if you have any idea! of how to keep the filteredData updated without making a for each in the changeListener i will be very happy and grateful. Thanks for reading!
Your algorithm is forcefully resetting all elements of filteredData everytime masterObservableList changes.
This is too exhaustive, as the listener can be triggered upon each item added or removed.
Maybe it's better to only add or remove the elements that have changed?
Repository.masterObservableList.addListener(new ListChangeListener<OrderVo>()
{
#Override
public void onChanged(ListChangeListener.Change<? extends OrderVo> change)
{
while(change.next()) {
if(change.wasAdded()) {
List added = change.getAddedSubList();
//add those elements to your data
}
if(change.wasRemoved()) {
List removed = change.getRemoved();
//remove those elements from your data
}
}
}
});
}

ArgumentOutOfRangeException running HtmlAgilityPack

I'm at my wits end. I keep getting this exception with HtmlAgilityPack whenever I attempt to select nodes using XPath. The problem remains even if I start a brand new solution with just this example (so it's not a problem with my application code interfering somehow. There's nothing wrong with the webpage, or my internet connection or anything like that. I know I've had this working before. I even suspected a corrupted dll somehow and re-downloaded it, but to no avail. Any ideas??
using System;
using HtmlAgilityPack;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var web = new HtmlWeb();
var doc = web.Load("http://www.google.com");
var root = doc.DocumentNode;
var links = root.SelectNodes("//a");
// Error! ArgumentOutOfRangeException: Index was out of range.
// Must be non-negative and less than the size of the collection.
}
}
}
/*
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
at System.ThrowHelper.ThrowArgumentOutOfRangeException()
at HtmlAgilityPack.HtmlNodeNavigator.MoveToFirstChild()
at MS.Internal.Xml.XPath.XPathDescendantIterator.MoveNext()
at MS.Internal.Xml.XPath.DescendantQuery.Advance()
at MS.Internal.Xml.XPath.XPathSelectionIterator.MoveNext()
at HtmlAgilityPack.HtmlNode.SelectNodes(String xpath)
at ConsoleApplication1.Program.Main(String[] args)
*/
edit:
Well...I'm not sure how it happened or what it did, but I found the .dll installed in a GAC_MSIL folder. Removing that immediately resolved the issue. So, nevermind!

Resources