Hallo,
ich möchte Daten aus einer Datenbank in ein Array speichern und dieses dann in Excel ausgeben.
Dies habe ich wie auf dieser Seite beschrieben gemacht:
http://support.microsoft.com/kb/306023/de Artikel-ID: 306023
Mein Problem, ist aber das nur die letzte Zeile für alle Einträge ausgegeben wird
wenn ich zb eine Matrix haben möchte
1 2 3
4 5 6
7 8 9
bekomme ich in Excel eine Matrix nur aus den letzten Zeilen
7 8 9
7 8 9
7 8 9
kann mir bitte jemand sagen, wo der Fehler ist und wie ich ihn beheben kann?
Danke
ich möchte Daten aus einer Datenbank in ein Array speichern und dieses dann in Excel ausgeben.
Dies habe ich wie auf dieser Seite beschrieben gemacht:
http://support.microsoft.com/kb/306023/de Artikel-ID: 306023
Mein Problem, ist aber das nur die letzte Zeile für alle Einträge ausgegeben wird
wenn ich zb eine Matrix haben möchte
1 2 3
4 5 6
7 8 9
bekomme ich in Excel eine Matrix nur aus den letzten Zeilen
7 8 9
7 8 9
7 8 9
kann mir bitte jemand sagen, wo der Fehler ist und wie ich ihn beheben kann?
Danke
Code:
using System;
using objExcel = Microsoft.Office.Interop.Excel;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
objExcel.Application appExcel;
objExcel.Workbooks objBooks;
objExcel.Workbook objBook;
objExcel.Sheets objSheets;
objExcel.Worksheet objSheet;
objExcel.Range objRange;
object objtemp = Application.StartupPath + "/test.xlsx";
object objMissing = Type.Missing;
appExcel = new objExcel.Application();
objBooks = appExcel.Workbooks;
objBook = objBooks.Add(objtemp);
objSheets = objBook.Worksheets;
objSheet = (objExcel.Worksheet)objBook.Worksheets.get_Item("Info");
objRange = (objExcel.Range)objSheet.Cells[3, 1];
objRange.Value2 = null;
object[] test = new object[5];
int a = 1;
for (int i = 1; i < 4; i++)
{
test[0] = a.ToString();
a += 1;
test[1] = a.ToString();
a += 1;
test[2] = a.ToString();
a += 1;
objRange = objSheet.get_Range("A1", "C1");
objRange = objRange.get_Resize(i, 5);
objRange.Value2 = test;
}
}
}