question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Active tab is not set correctly on inserting sheet at the front

See original GitHub issue

Do you want to request a feature or report a bug?

  • Bug
  • Feature

Version of ClosedXML

0.94.2 and latest build

What is the current behavior?

Given a new empty excel file with one sheet.

Execute the following code:

this.worksheet = this.workbook.Worksheets.Add("NewFrontSheet", 1);

Afterwards open the file in Excel. Note that both the first and second sheet are selected and the first sheet is active.

image

If the sheet is added in position 2 note that the result will have only one sheet active and selected.

image

What is the expected behavior or new feature?

The active worksheet should correctly be kept when adding a new sheet in first position.

Did this work in previous versions of our tool? Which versions?

unknown

Reproducibility

Code to reproduce problem:

class Program
	{
		private XLWorkbook workbook;
		private IXLWorksheet worksheet;

		static void Main(string[] args)
		{
			Program p = new Program();
			p.Test();
		}

		private void Test()
		{
			this.workbook = new XLWorkbook(@"T:\tmp\test.xlsx");
			this.worksheet = this.workbook.Worksheets.Add("NewFrontSheet", 1);
			this.workbook.Save();
		}
	}


test.xlsx result.xlsx

I assume this is an issue with how workbookView.activeTab is handled, since TabActive does return false for the single sheet directly after new XLWorkbook(…). The initial value in workbook.xml is not set (should default to 0).

I hope this helps.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ChristophHornungcommented, Apr 1, 2020

@Pankraty Yes, that fixes the problem I am seeing. Thanks a lot! ✨

0reactions
ChristophHornungcommented, Apr 1, 2020

@Pankraty If I select the second sheet activeTab is set to ‘1’. TwoSheetsSecondSelected.xlsx

Read more comments on GitHub >

github_iconTop Results From Across the Web

Set page setup attributes for more than one sheet in Excel
Method 1: Change a group of worksheets​​ To apply page setup attributes to a group of worksheets in a workbook, follow these steps:...
Read more >
Change VBA code to send only active worksheet
This code works fine for sending the entire workbook but I need it to send only the active sheet that I'm working on....
Read more >
Unable to Insert a New Worksheet
To check if this is the case, go to the “Review” tab and click on “Protect Workbook”. If you are prompted to unprotect...
Read more >
Excel Sheet Tabs Are Missing at the Bottom of a Workbook FIX
If you ever find “Missing Sheet Tabs ” from the bottom left corner of your Microsoft ... How to fix Excel has stopped...
Read more >
Excel 2016 - Page Break - How to Set Adjust Insert ... - YouTube
In this Microsoft Excel 2016 tutorial shows you how to insert, ... and a Bibliography Save a Document Correct Errors as You Type...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found