Excel
A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
1,955 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I have an excel in which data is large i.e.2000 characters for a cell.Since no wrap was there I have added the wrap handling and extra code so that I am able to scroll properly.
But column width is not getting set.
It is 273+ only.Tried autofitcolumn as well but no luck.
Below is the code :
w_Val = "2000 CHARACTERS VALUE"
StringBuilder wrappedText = new StringBuilder();
int w_currentIndex = 0;
while (w_currentIndex < w_Val.length()) {
int endIndex = Math.min(w_currentIndex + 200, w_Val.length());
// If there is no space, ensure we don't split words in the middle
if (endIndex < w_Val.length() && w_Val.charAt(endIndex) != ' ') {
int lastSpace = w_Val.lastIndexOf(' ', endIndex);
if (lastSpace > w_currentIndex) {
endIndex = lastSpace;
}
}
// Append the current line
wrappedText.append(w_Val, w_currentIndex, endIndex).append("\n");
// Move to the next part of the text
w_currentIndex = endIndex;
// Skip any spaces at the start of the next line
while (w_currentIndex < w_Val.length() && w_Val.charAt(w_currentIndex) == ' ') {
w_currentIndex++;
}
}
w_Val = wrappedText.toString().trim();
a_cell.setValue(w_Val);
Style w_style = a_cell.getStyle();
w_style.setTextWrapped(true);
a_cell.setStyle(w_style);
a_workSheet.setColumnWidth(3, 150);
a_workSheet.calculateFormula(true, true);