We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Including blank cells in worksheet

Hi,
I need to include blank cell in worksheet but it does not work.
This is my code:

ExcelEngine excelEngine = new ExcelEngine();

IApplication application = excelEngine.Excel;

application.DefaultVersion = ExcelVersion.Excel2013;

IWorkbook workbook = application.Workbooks.Create(1);

IWorksheet worksheet = workbook.Worksheets[0];

 

worksheet[1, 1].Text = "";

worksheet[1, 2].Text = "";

       

using (FileStream fileStream = new FileStream(filePath, FileMode.CreateNew))

{           

    worksheet.SaveAs(fileStream, ";", Encoding.Default);                                                               

}

workbook.Close();

excelEngine.Dispose();           


Output expected: ;;


How can I fix? 



3 Replies

PK Prakash Kumar D Syncfusion Team November 8, 2018 11:37 AM UTC

Hi Mini, 
 
Thank you for contacting Syncfusion support. 
 
It is not possible to include blank cells in an empty worksheet of Microsoft Excel (CSV format). You can include blank cells only in between cells with values. This is a behavior of Microsoft Excel, XlsIO does the same. 
 
However, you can achieve your requirement by using following code  
 
Code snippet: 
 
sheet["A1:C1"].Text = "blank cells"; 
sheet["A1:C1"].Text = ""; 
 
Note: In an empty worksheet, the used range of worksheet will be null in XlsIO. Hence the blank cells are not preserved. By assigning a text to a range, which will be included in used range and its preserve the blank cells. 
 
Regards, 
Prakash Kumar 



MD Mini Dev November 8, 2018 11:40 AM UTC

there was a miss understanding.
I solved with 
worksheet.SetBlank();


PK Prakash Kumar D Syncfusion Team November 9, 2018 06:26 AM UTC

Hi Mini, 
  
Thank you for updating us. 
  
We are glad that your issue is resolved. Please get back to us if you need further assistance. 
  
Regards, 
Prakash Kumar 


Loader.
Up arrow icon