Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Retrieving Data from Excel Pivot tables into Datatable

Hi,

Has any body so far retrieved Excel pivot data in to ADO.net?

If so please let me know your approach. For some reason i get more
exceptions to my pivottable/cache objects than values.

I am using the below namespaces. Pl. let me kowif i missing any?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Office = Microsoft.Office.Core;
using Excel = Microsoft.Office.Interop.Excel;
using System.Runtime.InteropServices;
using Microsoft.VisualStudio.Tools.Applications.Runtime;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Data.Common;


And here is all the code: i have a ui from which i get the location of the
excel spreadsheet.

namespace _
{
public partial class Form1 : Form
{
public Excel.Application xlApp;
public Excel._Workbook xlWkBk;
public Excel.Workbooks xlBooks;
public Excel.Sheets xlSheets;
public Excel.Worksheet xlWkSheet;
public Excel.PivotTable xlPvt;
public Excel.PivotCache xlCche;
public Excel.PivotFields xlFlds;
public Excel.PivotItems xlPvtItms;
//public OleDbConnection cnExcel;
//public OleDbDataAdapter daExcel;
public DataTable dt;
public DataAdapter da;
public DataSet ds;
int i,j;

public Form1()
{
InitializeComponent();
xlApp = new Excel.Application();
if (xlApp == null)
{
MessageBox.Show("ERROR: EXCEL couldn't be started!");
System.Windows.Forms.Application.Exit();
}
xlApp.Visible = false;

}

private void button1_Click(object sender, EventArgs e)
{
//xlBooks = new Excel.Workbooks();
xlWkBk = xlApp.Workbooks.Open(textBox1.Text, 0, true, 5,
System.Reflection.Missing.Value, System.Reflection.Missing.Value, true,
Excel.XlPlatform.xlWindows, System.Reflection.Missing.Value, false, false,
System.Reflection.Missing.Value, false, true,
Excel.XlCorruptLoad.xlNormalLoad);
if (xlWkBk == null)
{
MessageBox.Show("ERROR: EXCEL file couldn't be started!");
System.Windows.Forms.Application.Exit();
}
xlWkSheet = (Excel.Worksheet) xlWkBk.ActiveSheet;
xlPvt = (Excel.PivotTable)xlWkSheet.PivotTables(1);
xlCche = (Excel.PivotCache)xlPvt.PivotCache();
MessageBox.Show(xlCche.BackgroundQuery.ToString()) ;
label1.Text = xlCche.Connection.ToString();
textBox2.Text = xlPvt.Name.ToString();
}

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
xlWkBk.Close(false, System.Reflection.Missing.Value, false);
xlApp.Workbooks.Close();
xlApp.Quit();
}
}
}

Thank you.
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2007 - Subtotals Below the Data in Pivot Tables TB in DC Excel Discussion (Misc queries) 2 November 3rd 08 02:19 AM
Building pivot tables in Excel 2007 based on existing pivot tables? [email protected] Excel Discussion (Misc queries) 4 December 26th 07 08:05 PM
Grouping data with Pivot Tables Excel 2003 Leefisher Excel Discussion (Misc queries) 1 September 17th 07 07:44 PM
Pivot table retrieving data from several worksheets Gizmo Excel Worksheet Functions 2 December 29th 04 02:43 AM
Retrieving Source Data From Pivot Table John Units Excel Programming 1 September 9th 03 08:07 PM


All times are GMT +1. The time now is 08:45 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"