We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Resizing table result in bold text

I am importing a csv file into an existing table in an Excel sheet and sometimes I want the headers to be visible and sometimes not. Whenever I choose to not show headers all text in my table becomes bold. Is there a way I can prevent this?
Attached is my Excel file with the table I am importing data into, the .csv file that is being imported and two PDFs that shows the reuslt with and without showing the header line.

I am using Aspose Cells Java 18.10

This is my code
License cellsLicense = new License();
cellsLicense.setLicense(“Aspose.Total.Java.lic”);

	File csvFile = new File("data.csv");
	List<String> csvData = Files.readAllLines(csvFile.toPath());
	int noOfColumns = 7; //StringUtils.countMatches(csvData.get(0), ",");		
	
	Workbook workbook = createWorkbookFromTemplate();		
	Worksheet sheet = workbook.getWorksheets().get(0);
	
	TxtLoadOptions options = new TxtLoadOptions();
 	options.setLanguageCode(CountryCode.USA);
	
	Cells cells = sheet.getCells();	
	cells.importCSV(csvFile.getAbsolutePath(), options , 1, 0);

	boolean hasHeaders = false; // Change to true for showing headers
	
	ListObject listObject = sheet.getListObjects().get(0);
	listObject.resize(0, 0, csvData.size() , noOfColumns, hasHeaders);
	listObject.setShowHeaderRow(hasHeaders);
		
	workbook.save(new File("generatedFile.pdf").getAbsolutePath());	

AsposeBoldTextReport.zip (95.6 KB)

Thanks
Rickard

@eklind,

Thanks for the template file, CSV file and sample code.

I noticed the behavior you have mentioned by using your sample code with your template file(s). Probably this is due to the fact (when hiding headers) new rows are inserted starting from the header row, which copies all formatting (bold) to all rows. I think you may easily cope with it by following a workaround, see the following code segment with updated lines of code (in bold) which works fine as I tested:
e.g
Sample code:


boolean hasHeaders = true;

ListObject listObject = sheet.getListObjects().get(0);
listObject.resize(0, 0, csvData.size() , noOfColumns, hasHeaders);

listObject.setShowHeaderRow(false);

Hope, this helps a bit.