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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Worksheet Excel, check for existence and add new values at the end of that worksheet

Thread ID:

Created:

Updated:

Platform:

Replies:

127800 Dec 9,2016 12:10 PM UTC Dec 14,2016 05:26 AM UTC ASP.NET MVC 6
loading
Tags: XlsIO
Testname
Asked On December 9, 2016 12:10 PM UTC

I Need something like this:

//1. Check if a worktsheet("((IWorksheet)workbook.worksheet[x]).Name)") exist

//1a) if true
-> Add at the last position( two values(2 cells, 2 different contents)(worksheet.UsedRange.LastRow ?!) for that existing sheet

//1b)if false
-> Create a new empty worksheet
-> Add at the last position two values(2 cells, 2 different contents) (worksheet.UsedRange.LastRow ?!)for that new sheet
        

How to build this ?!



Sudha Ramachandran [Syncfusion]
Replied On December 12, 2016 10:49 AM UTC

Hi, 

We have provided a simple sample based on you scenario in the below link. Please try the sample and let us know if this helps. 


Regards, 
Sudha R 


Testname
Replied On December 12, 2016 12:48 PM UTC

The more data I the more the cells get shifted. attachment

Attachment: tfs_3ec3ce46.7z

Testname
Replied On December 12, 2016 02:48 PM UTC

Ok, I solved the above mentioned issue, but I think I found a bug ?!





Running the same logic over:

string name="00_XXXXXXXXXXXXXXXXXX_XXX_XXX_XXX";

                if (workbook.Worksheets[name] != null)
                {
                    sheet = workbook.Worksheets[name];
                }
                else
                {
                    sheet = workbook.Worksheets.Create(name);
                }
                
over again will result in wrong results:

One time the tab name in Excel will be e.g:

"00_XXXXXXXXXXXXXXXXXX"        
"00_XXXXXXXXXXXXXXXXXX_XXX_X"    
"00_XXXXXXXXXXXXXXXXXX_XXX_XXX_X"

Maybe the length of the tab name depends on all elements in "workbook.Worksheets".

The problem here is if I read in the same file again, syncfusion will create a new sheet "workbook.Worksheets.Create(name)", because the library thinks the tab does not exist.
Actually this is true, because the string ("name") will be shortend, but actually it is always the same string.

What to do here ?!

Sridhar Sukumar [Syncfusion]
Replied On December 13, 2016 12:54 PM UTC

Hi, 

Query 

Response 

The problem here is if I read in the same file again, syncfusion will create a new sheet "workbook.Worksheets.Create(name)", because the library thinks the tab does not exist. 

Actually this is true, because the string ("name") will be shortend, but actually it is always the same string. 

  

What to do here ?! 

 
We can reproduce the issue. A support incident to track the status of this incident has been created under your account. Please log on to our support website to check for further updates. 
  
 

The more data I the more the cells get shifted. attachment 

 
The column can be re-located using the below code. 
 
Please refer the following code snippet in your sample to achieve this 
 
Code snippet: 
if (usedRange.Column < 1) 
    column = 1; 
 
  
Please let me know if you have any questions. 
  
Regards, 
Sridhar S 


mvxyc
Replied On December 13, 2016 01:16 PM UTC

thanks :)

Ranjani Prabhakaran [Syncfusion]
Replied On December 14, 2016 05:26 AM UTC

Dear Customer, 
  
Thank for the update. Please do reach us if you need any assistance in future. 
  
Regards, 
  
Ranjani

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;