Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 20th, 2006, 10:49 AM
Registered User
 
Join Date: Sep 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Pasing parameters to Spreadsheet

I have a gridview and I want to be able to pass the values from the gridview to an existing excel document. I want to be able to use the Excel object model. So far I have managed to open my existing document but I havent figure out how to pass the values. ANy suggestions? Thank you

 
Code:
protected void BtnAnalysis_Click(object sender, EventArgs e)
Code:
    {
        Microsoft.Office.Interop.Excel.Application m_objExcel;
        Microsoft.Office.Interop.Excel._Workbook m_objBook;
        Microsoft.Office.Interop.Excel.Workbooks m_objBooks;
        Microsoft.Office.Interop.Excel.Sheets m_objSheets;
        Microsoft.Office.Interop.Excel._Worksheet m_objSheet;
        Microsoft.Office.Interop.Excel.Worksheets ExcelWorkSheets;
        Microsoft.Office.Interop.Excel.Font m_objFont;

        m_objOpt = System.Reflection.Missing.Value;
        m_objExcel = new Microsoft.Office.Interop.Excel.Application();
        m_objBooks = (Microsoft.Office.Interop.Excel.Workbooks)m_objExcel.Workbooks;
        m_objBook = (Microsoft.Office.Interop.Excel.Workbook)(m_objBooks.Add(m_objOpt));
        m_objExcel.Visible = true;



        string workbookPath = "c:/BillingAnalysis.xls";
        m_objBook = m_objExcel.Workbooks.Open(workbookPath,
            0, false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "",
            true, false, 0, true, false, false);



        }




}
 
Old September 22nd, 2006, 07:31 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

I don't think this is VBA. :D

Try "Integrating Excel and Access" by OReilly. I think you need that level of depth.



mmcdonal
 
Old September 22nd, 2006, 11:15 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Post your comment to the C# forum:

http://p2p.wrox.com/c-22/

If your list control is using a DataSet as its record source, you could write the values from the relevant DataTable to Excel using nested foreach loops, something like:

Code:
DataTable table = dataSet.Tables[0];
int ColumnIndex=0; 
foreach(Datacolumn col in table.Columns) {   
  ColumnIndex++;
  excelObject.Cells[1, ColumnIndex]=col.ColumnName;
} 
int rowIndex=0; 
foreach(DataRow row in table.Row) {         
  rowIndex++;       
  ColumnIndex=0;         
  foreach(DataColumn col in table.Columns) {  
    ColumnIndex++;                
    excelObject.Cells[rowIndex+1, ColumnIndex]=row.Cells[col.ColumnName].Text;         
  }
}

HTH,

Bob







Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel Spreadsheet Help SteveV VBScript 0 October 10th, 2006 04:42 PM
Excel Spreadsheet Help SteveV BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 0 October 10th, 2006 04:41 PM
Excel Spreadsheet Help SteveV BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 0 October 10th, 2006 04:40 PM
Pasing parameters to Spreadsheet Azhavee grajeda Access VBA 0 September 20th, 2006 10:49 AM
Export a spreadsheet Corey Access 0 November 22nd, 2005 03:42 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.