Click here to Skip to main content
15,913,610 members
Home / Discussions / C#
   

C#

 
GeneralRe: Floating/Dockable form Pin
lsconyer7-Apr-08 3:11
lsconyer7-Apr-08 3:11 
QuestionRegarding printing of Windows forms [modified] Pin
manikandanid7-Apr-08 2:23
manikandanid7-Apr-08 2:23 
GeneralDynamically add TabPages to my form depending on the number of worksheets in a spreadsheet Pin
Walaza7-Apr-08 2:18
Walaza7-Apr-08 2:18 
GeneralRe: Dynamically add TabPages to my form depending on the number of worksheets in a spreadsheet [modified] Pin
lsconyer7-Apr-08 2:32
lsconyer7-Apr-08 2:32 
GeneralRe: Dynamically add TabPages to my form depending on the number of worksheets in a spreadsheet Pin
darkelv7-Apr-08 4:14
darkelv7-Apr-08 4:14 
GeneralRe: Dynamically add TabPages to my form depending on the number of worksheets in a spreadsheet Pin
Walaza7-Apr-08 4:54
Walaza7-Apr-08 4:54 
GeneralRe: Dynamically add TabPages to my form depending on the number of worksheets in a spreadsheet Pin
lsconyer7-Apr-08 5:07
lsconyer7-Apr-08 5:07 
GeneralRe: Dynamically add TabPages to my form depending on the number of worksheets in a spreadsheet Pin
Walaza7-Apr-08 5:59
Walaza7-Apr-08 5:59 
Thank you so much, I am making so much progress in one day! The problem is, it only shows the data of only one worksheet. It shows the tabs and their worksheets names but does not add the datagrid and the data to the tabpage. What could I be doing wrong, here's the code:
//This takes the Excel file from a specific location
//and displays it in the datagrid
private void btnOpenFile_Click(object sender, EventArgs e)
{


// prepare open file dialog to only search for excel files
this.ofd.FileName = "*.xls";
if (this.ofd.ShowDialog() == DialogResult.OK)
{
try
{
// Here is the call to Open a Workbook in Excel
// It uses most of the default values (except for the read-only which we set to true)
Microsoft.Office.Interop.Excel.Workbook theWorkbook = ExcelObj.Workbooks.Open(ofd.FileName, 0, true, 5,
"", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, true, true);

// get the collection of sheets in the workbook
Microsoft.Office.Interop.Excel.Sheets sheets = theWorkbook.Worksheets;

//theWorkbook.Worksheets[sheets];

// get the first and only worksheet from the collection of worksheets
Microsoft.Office.Interop.Excel.Worksheet worksheet = (Microsoft.Office.Interop.Excel.Worksheet)sheets.get_Item(1);


TabControl tbControl = new TabControl();
this.Controls.Add(tbControl);
tbControl.Dock = DockStyle.Bottom;
tbControl.Height = 660;
TabPage page;
//DataGridView dgv;

foreach (Worksheet sheet in sheets)
{
page = new TabPage(sheet.Name.ToString());
//dgOutput = new DataGridView();


//get start and end rows
Object[] startRow = { worksheet.get_Range("A4", "O4") };
int endRow = worksheet.Cells.SpecialCells(XlCellType.xlCellTypeLastCell, Type.Missing).Row;


//Check the columns...Removed

// loop through the rows of the spreadsheet and place each row in the datagrid
for (int i = 5; i <= endRow; i++)
{
Microsoft.Office.Interop.Excel.Range range = worksheet.get_Range("A" + i.ToString(), "Z" + i.ToString());
System.Array myvalues = (System.Array)range.Cells.Value2;

string[] strArray = ConvertToStringArray(myvalues);

//Add the rows from the spreadsheet to the datagrid
DataGridViewRow row = new DataGridViewRow();
Object[] vals = strArray;
row.CreateCells(dgOutput, vals);
dgOutput.Rows.Add(row);
}

page.Controls.Add(dgOutput);
tbControl.TabPages.Insert(0, page);
}
}
catch (Exception EX)
{
MessageBox.Show("Error: " + EX.Message, "Error opening Excel..");
}
}

Mvelo Walaza
Developer
Telkom SA

GeneralRe: Dynamically add TabPages to my form depending on the number of worksheets in a spreadsheet Pin
lsconyer7-Apr-08 6:57
lsconyer7-Apr-08 6:57 
GeneralRe: Dynamically add TabPages to my form depending on the number of worksheets in a spreadsheet Pin
Walaza7-Apr-08 20:31
Walaza7-Apr-08 20:31 
GeneralRe: Dynamically add TabPages to my form depending on the number of worksheets in a spreadsheet Pin
lsconyer8-Apr-08 0:37
lsconyer8-Apr-08 0:37 
GeneralRe: Dynamically add TabPages to my form depending on the number of worksheets in a spreadsheet Pin
Walaza8-Apr-08 2:52
Walaza8-Apr-08 2:52 
GeneralRe: Dynamically add TabPages to my form depending on the number of worksheets in a spreadsheet Pin
lsconyer8-Apr-08 3:30
lsconyer8-Apr-08 3:30 
GeneralRe: Dynamically add TabPages to my form depending on the number of worksheets in a spreadsheet Pin
Walaza8-Apr-08 4:33
Walaza8-Apr-08 4:33 
GeneralRe: Dynamically add TabPages to my form depending on the number of worksheets in a spreadsheet Pin
Walaza8-Apr-08 20:08
Walaza8-Apr-08 20:08 
GeneralRe: Dynamically add TabPages to my form depending on the number of worksheets in a spreadsheet [modified] Pin
lsconyer9-Apr-08 1:48
lsconyer9-Apr-08 1:48 
GeneralRe: Dynamically add TabPages to my form depending on the number of worksheets in a spreadsheet Pin
Walaza9-Apr-08 3:30
Walaza9-Apr-08 3:30 
GeneralRe: Dynamically add TabPages to my form depending on the number of worksheets in a spreadsheet Pin
lsconyer9-Apr-08 3:46
lsconyer9-Apr-08 3:46 
GeneralRe: Dynamically add TabPages to my form depending on the number of worksheets in a spreadsheet Pin
Walaza9-Apr-08 4:21
Walaza9-Apr-08 4:21 
GeneralRe: Dynamically add TabPages to my form depending on the number of worksheets in a spreadsheet Pin
lsconyer9-Apr-08 6:09
lsconyer9-Apr-08 6:09 
QuestionHow to write a text in a video files Pin
Smithakrishnan7-Apr-08 2:16
Smithakrishnan7-Apr-08 2:16 
GeneralCustom treeview woes Pin
lsconyer7-Apr-08 2:14
lsconyer7-Apr-08 2:14 
Generalgprs Pin
sbk197-Apr-08 1:52
sbk197-Apr-08 1:52 
GeneralRe: gprs Pin
Dave Kreskowiak7-Apr-08 4:24
mveDave Kreskowiak7-Apr-08 4:24 
GeneralRe: gprs Pin
Luc Pattyn7-Apr-08 4:40
sitebuilderLuc Pattyn7-Apr-08 4:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.