I am using the following code to combine 2 workbooks into one. The resultant file has the initial sheets grouped and when you type anything in a cell it placed in all the cells except the 2 workbook.
' Combine workbooks from the previous years For Each fi In aryFi blndbFound = False
If fi.Name.Trim.Length = "State Stats-FY".Length + Mid(txtFY.Text, 3, 2).Length + ".xls".Length Then If fi.Name.IndexOf("State Stats-FY" & Mid(txtFY.Text, 3, 2) & ".xls", 0, StringComparison.CurrentCulture) >= 0 Then blndbFound = False Else blndbFound = True End If End If
If blndbFound Then Dim StatsWorkbook As Workbook = New Workbook StatsWorkbook.Open(Application.StartupPath & "\" & fi.Name, FileFormatType.Excel97To2003)
workbook.Combine(StatsWorkbook)
workbook.Save(Application.StartupPath & "\State Stats-FY" & Mid(txtFY.Text, 3, 2) & ".xls", FileFormatType.Excel97To2003) End If Next
We are unable to reproduce the issue. Please forward us more details about the issue. Also, please send us the two Xls files so that we can combine those and observe the issue.
Well, I use the following sample code to combine your templates (from your previous post) which works fine without your mentioned grouping sheets issue. Workbook MasterTemplate = new Workbook(“e:\test\combines\State+Stats-FY11.xls”); Workbook SkeletonTemplate = new Workbook(“e:\test\combines\State+Stats-fy10.xls”); MasterTemplate.Combine(SkeletonTemplate); MasterTemplate.Save(“e:\test\combines\outbook1.xls”);
Please create a sample console application, zip it and post it here, to show or reproduce the issue here on our end. We will check your issue soon.
Sorry for not getting back to you sooner about this. I was busy working on another problem. But if you look at the State Stats fy 11, the work sheets are already grouped. Why? I have looked at the code to see as to why it would group the sheets.
Part of the code I use is the following for the individual sheets.
I still could not find the issue. I used your template file … F10.xls, copied all the sheets into a new workbook and save as the file, the output file is fine. It has not grouped sheets.
Sample code:
Dim template As New Workbook(“e:\test\State+Stats-fy10.xls”) Dim workbook As New Workbook() workbook.Worksheets.Clear() For Each sheet As Worksheet In template.Worksheets Dim i As Integer = workbook.Worksheets.Add() workbook.Worksheets(i).Copy(sheet) workbook.Worksheets(i).Name = sheet.Name
Next sheet
workbook.Save(“e:\test\myState+Stats-fy11.xls”)
Attached is the output file, please check it.
If you still find the issue, kindly create a sample console application and zip it to post it here to reproduce the issue on our end, so that we may look into your issue soon.
Each sheet in FY 11 is an individual sheet. The firs thing I do is open a summary page as a designer file, then I add each sheet to it that is FY 11. Then I save it as the FY11 state stats workbook. At the end I combine FY11 and FY10 together.
If I have the time I will attempt to generate a program that will do this. Bu you will have to have all the individual sheets for FY11 along with FY10.
I guess the question I need to ask do you know when I say they are grouped together? If you open the FY11 workbook and on the second tab at the bottom go to say A12 and start typing. This places information on all sheets at this place. The only way to stop it is go to the tabs at the bottom and right click and tell it ungroup.
Well, I understand, opening your FY11.xls file into MS Excel does produce the issue as you described, but we got to know the steps involved to generate such a file. Therefore, we requested you to create a sample application and post it here, it will help us really to trace and figure out the issue very soon.
<![endif]–> I think we have found your mentioned issue, we need to set license (I was not doing this) before testing your scenario with your file(s).
For your information, if Workbook A combines Workbook B, the active worksheet of
B will still be active in Combined A. So, there are two active worksheets, and are
grouped worksheets displayed in MS Excel. We could not fix it because we do not know which active
worksheet should be not active. Please set Workbook.Worksheets.
ActiveSheetIndex property after workbook.Combine method. I should fix your issue.
Ok, guys I got a sample project. No it did not work as you suggested above. In fact the items are being grouped before the combine method. Attached is the sample project with all the stuff. You should be able to restore and run. Add license and run.
After looking your code segments in your project a bit, you did not do what we suggested in the previous post. Please set the active worksheet after Combine method. See following code segment (add the bold line): workbook.Combine(StatsWorkbook) workbook.worksheets. ActiveSheetIndex =0;// set the active sheet.