Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Tue Feb 14, 2023 9:13 pm

I'm using an xlsx file as a template for smart markers and have to modify the file frequently. Each time I do so, I have to remember to select cell A1 before I save, or else the resulting file generated by Spire.XLS will still have the cell selected which I last had clicked on. Due to dynamically added rows, this might mean the spreadsheet initially opens scrolled way down to the bottom. I want to make sure the spreadsheet always opens to the top of the document. Ideally, I would prefer nothing selected, but would settle for top-left cell selected.

What does Worksheet.Unselect() do? I can't see that it has any effect.

I have tried calling worksheet.SetActiveCell(worksheet.Range["A1"]). It does select A1, but it leaves an odd gray half-selected look to the previous selected cell, and stays scrolled down to the bottom with the previously selected cell.

How can I accomplish this?

Thanks,
Danny

Edit: .NET FreeSpire.XLS version 12.7

DaMiller
 
Posts: 8
Joined: Thu Jan 12, 2023 9:12 pm

Wed Feb 15, 2023 10:30 am

Hi Danny,

Thanks for your inquiry.
I did an initial test, but I did not reproduce your issue. to help us do an accurate investigation, could you please provide us with the following messages? You can send them to us via email (support@e-iceblue.com) or attach them here. Thanks for your assistance.
1) your full code and test document.
2) your application type, such as Console App .Net Framework 4.8.

Sincerely,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Wed Feb 15, 2023 5:51 pm

Disregard my earlier mention of a DataTable, as it ended up being irrelevant to the issue.

Still, I remain unsure of how to unselect any existing active cells.

Template.xlsx is in attached .zip file.
Using FreeSpire.XLS 12.7 in a .NET 6.0 command line project, here is my full code:

Code: Select all
using Spire.Xls;

using Workbook workbook = new Workbook();
using (var stream = new FileStream("Template.xlsx", FileMode.Open, FileAccess.Read))
{
   workbook.LoadFromStream(stream);
}
Worksheet sheet = workbook.Worksheets[0];

sheet.SetActiveCell(sheet["A1"]);

workbook.SaveToFile("result.xlsx", ExcelVersion.Version2016);


Here is what the result.xlsx ends up looking like:
screenshot.png
screenshot.png (8.25 KiB) Viewed 965 times


If I add a lot of rows to the spreadsheet and scroll down to select a bottom row before i save and close the document and run the program, then the effect is worse, with the document scrolled down.
Attachments
Template.zip
(6.06 KiB) Downloaded 394 times

DaMiller
 
Posts: 8
Joined: Thu Jan 12, 2023 9:12 pm

Thu Feb 16, 2023 11:58 am

Hi,

Thanks for your feedback.
I noticed your issue, then I searched our bug tracking system and found that the issue did exist, but it has been fixed, I tested your document with our latest Spire.XLS_13.2.4, it works fine, you can download it from this link(https://www.e-iceblue.com/Download/download-excel-for-net-now.html) and have a test. Since we irregularly maintain our free version, for your situation, I suggest you use our commercial version, which is more powerful and stable. In addition, we are willing to offer you a temporary license (one month free) to help you evaluate our products better. If you need, just let us know.

Sincerely,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Tue Oct 08, 2024 8:22 pm

SetActiveCell() now functions properly, but it does not scroll the worksheet into view of the active cell. Is there a way to scroll to top, or scroll to specific position?

Though this may seem a different topic, I mentioned the problem previously in this thread, hence asking here.

DaMiller
 
Posts: 8
Joined: Thu Jan 12, 2023 9:12 pm

Wed Oct 09, 2024 8:46 am

Hello,

Thanks for your inquiry. You can refer to the code below to set the scrolling position. If you have any other questions, please feel free to write to me.
Code: Select all
   //Display from the first row after opening
   sheet.FirstVisibleRow = 1;
   //Display from the first column after opening
   sheet.FirstVisibleColumn = 1;

Sincerely,
Amin
E-iceblue support team
User avatar

Amin.Gan
 
Posts: 283
Joined: Mon Jul 15, 2024 5:40 am

Wed Oct 09, 2024 3:43 pm

It works perfectly, thank you!

DaMiller
 
Posts: 8
Joined: Thu Jan 12, 2023 9:12 pm

Thu Oct 10, 2024 1:15 am

Hello,

Thanks for your reply.
I'm glad to hear this news. If you have any other questions, please feel free to write to me.

Sincerely,
Amin
E-iceblue support team
User avatar

Amin.Gan
 
Posts: 283
Joined: Mon Jul 15, 2024 5:40 am

Return to Spire.XLS