tutorials.de Buch-Aktion 05/2012
ERLEDIGT
NEIN
ANTWORTEN
1
ZUGRIFFE
600
EMPFEHLEN
  • An Twitter übertragen
  • An Facebook übertragen
AUF DIESES THEMA
ANTWORTEN
  1. #1
    gloomy87 gloomy87 ist offline Grünschnabel
    Registriert seit
    Nov 2010
    Beiträge
    1
    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

    Code :
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    
     
    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; 
                }
                }
            }
     

  2. #2
    tequila slammer tequila slammer ist offline Mitglied Gold
    Registriert seit
    Aug 2006
    Beiträge
    204
    Die Sache ist ganz klar. Schau dir mal an wie du das Array erstellst, dann wird dir auffallen, dass du immer an die gleiche Position schreibst. Außerdem solltest du kein Object-Array erstellen, wenn du nur int-Werte reinschreibst.
     

Ähnliche Themen

  1. Problem beim Speichern in DB
    Von Micha2006 im Forum Relationale Datenbanksysteme
    Antworten: 8
    Letzter Beitrag: 23.01.07, 22:02
  2. Probleme beim speichern eines Excel-workbooks
    Von Schmatz001 im Forum .NET Datenverwaltung
    Antworten: 2
    Letzter Beitrag: 24.10.06, 15:24
  3. Antworten: 2
    Letzter Beitrag: 24.08.06, 09:31
  4. Antworten: 10
    Letzter Beitrag: 06.12.05, 21:12
  5. Problem beim Speichern Oo
    Von Joke2k im Forum Cinema 4D
    Antworten: 2
    Letzter Beitrag: 30.07.05, 14:03

Stichworte