0

I'm developing an Excel Addin that fills a sheet with information from a web page.

There's a button that shows two more columns, I get the information and fill the columns, and after that, if the button "Show this columns" is not pressed, I hide them:

Range gColumn = swatDataSheet.Columns["G"];
Range hColumn = swatDataSheet.Columns["H"];

if (!showOmniWorksButton.Checked)
{
    gColumn.Hidden = true;
    hColumn.Hidden = true;
}
else
{
    gColumn.Hidden = false;
    hColumn.Hidden = false;
}

The first time everything works correctly, but if I refresh the sheet and fill it again, everything starts from the column I've hidden before, even if it's not hidden now. If my data starts on A1, after remove and fill again it starts from the column I hid, G1.

Is this a bug or am I doing something wrong?

Thank you.

AlexTemina
  • 139
  • 11

1 Answers1

0

Don't see anything wrong in the pasted code so I'm guessing it might have something to do with the code that fills the information.

How do you fill the data? Do you just start filling the columns from the currently selected one? If so maybe that is the reason, you algorithm just fills right from the selection. Try to select a cell from column G when you first run the filling.

Mitja Bezenšek
  • 2,503
  • 1
  • 14
  • 17
  • I start from A1. First I put all the headers, one in each column, and then I put all the information, for each row I fill all the fields. So I fill columns starting on A1. It's so strange the second time, `(range.Cells[rowIndex, 1] as Range).Value2 = "Queries:";` being `rowIndex = 1` fills the cell G1 instead of A1... why? range is `sheet.UsedRange`. – AlexTemina Mar 26 '13 at 13:37
  • Ok, I finally found the answer. I was creating the range everytime as "UsedRange". When the worksheet was empty, the range started in A1 but if I hide some fields they are considered as "Used" so that's why my worksheet was being filled from here. Thank you @MitjaBezenšek, you made me think on the solution. – AlexTemina Mar 26 '13 at 13:53
  • I'm glad you figured it out. – Mitja Bezenšek Mar 27 '13 at 18:39