We are currently using Aspose.words 15.8.0 jar to extract data from an html file using Java. Upon checking with a sample document, we found that when a table in html doc contains only chinese characters, cell width value returned is improper in aspose API. Similary when I try the same with english content, cells width are fine & it equals total table width, where as for Chinese text cell width exceeds way above actual table width specified.
Code used to achieve this is given below:
import java.io.InputStream;
import com.aspose.words.Cell;
import com.aspose.words.CellCollection;
import com.aspose.words.Document;
import com.aspose.words.LoadOptions;
import com.aspose.words.NodeList;
import com.aspose.words.RowCollection;
import com.aspose.words.Table;
public class AsposeChineseCellWidthIssue {
public static void main(String[] args){
try {
//Read document from path & convert it to stream
LoadOptions loadOptions = new LoadOptions();
Document doc = new Document(documentStream, loadOptions);
NodeList tableNodes = doc.selectNodes("//Table");//No I18N
for(Table table : tableNodes){
RowCollection tableRows = table.getRows();
for(int i=0; i<tableRows.getCount(); i++){
CellCollection cellCols = tableRows.get(i).getCells();
double totalCellWidth = 0;
for(int j=0; j < cellCols.getCount(); j++){
Cell curCell = (Cell) cellCols.get(j);
double curCellWidth = curCell.getCellFormat().getWidth();
totalCellWidth += curCellWidth;
}
System.out.println(“Total cell width is::” + totalCellWidth + " pts But actual table width is::" + table.getPreferredWidth().getValue() + " pts");
}
}
}catch(Exception e) {
}
}
}
FYI, documents attached.files.zip (2.3 KB)