473,395 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Wie kann ich mein Array() vollständig in eine Excel Zelle bringen.

Hi,

ich habe ein eindimesionales Array dessen ca. 5 Werte (01234) ich in
_eine_ Zelle schreiben will.
Um in Excel zu schreiben habe ich folgende Sub geschrieben:
Private Sub ExcelAusgabe(ByVal Wert() As Integer)

Dim xlApp As Excel.Application
Dim xlMappe As Excel.Workbook
Dim xlBlatt As Excel.Worksheet
Dim xlZelle As Excel.Range
Dim intZeilen As Integer
Dim EigDat As String

'Pfad zu den eigenene Dateien hier ablegen.
EigDat =
Environment.GetFolderPath(Environment.SpecialFolde r.Personal)

xlApp = New Excel.Application
xlApp.Visible = True
xlMappe = _
xlApp.Workbooks.Open(EigDat & "\MMSBest.xls")
xlBlatt = xlMappe.Worksheets(1)
xlZelle = xlBlatt.Range("A1")
intZeilen = xlZelle.CurrentRegion.Rows.Count
xlZelle.Offset(intZeilen, 0).Value = intZeilen
xlZelle.Offset(intZeilen, 1).Value = Now()

'Hier liegt das Problem, oder?
xlZelle.Offset(intZeilen, 2).Value = Wert
xlMappe.Save()
xlMappe.Close()
xlApp.Quit()

End Sub
Alles klappt bis auf den Fehler das in der entsprechenden Zelle für
"Wert" statt "01234" nur "0" steht.

Jemand ne Idee??

Nov 21 '05 #1
7 3437
Anhang:

xlZelle.Offset(intZeilen, 2).Value = CStr(Wert)

kompiliert nicht. Die Fehlermeldung lautet:
Der Wert des Typs "1-dimensionales Array von Integer" kann nicht zu
"String" konvertiert werden.

Gibt es da eine andere Funktion die ich verwenden kann, oder muß ich
das Array durchgehen (mit einem Do until GetArray.Lenght Loop) und
alles in eine String Variable speichern??
Wäre wohl ein Weg, scheint mir aber sehr umständlich.
Irgendein Profi hier der weiter weiß?

Nov 21 '05 #2
Mikq,

I know at least two persons active in this newsgroup who can answer as well
in good German, although one is from Austria.

However they will tell you that there are a lot of nice entwickler
newsgroups for dotnet.

By instance
microsoft.public.de.entwickler.dotnet.vb

Or ask your question in English here. We all want to deal in the answers you
know and in this newsgroups we come from all over the world and use English
as our communication language.

Thanks in advance

Cor
Nov 21 '05 #3
Dear Cor Ligthert [MVP]:

Sorry,
didn't want to be unpolite.

I'll try my best translating this in English:

I created a one-dimensional arry with roundabout 5 values (01234).
These values need to be written in _one_ Excel cell.

I wrote a little subroutine to do that:

Private Sub ExcelAusgabe(ByVal Wert() As Integer)

Dim xlApp As Excel.Application
Dim xlMappe As Excel.Workbook
Dim xlBlatt As Excel.Worksheet
Dim xlZelle As Excel.Range
Dim intZeilen As Integer
Dim EigDat As String

'Pfad zu den eigenene Dateien hier ablegen.
EigDat =
Environment.GetFolderPath(Environment.SpecialFolde r.Personal)

xlApp = New Excel.Application
xlApp.Visible = True
xlMappe = _
xlApp.Workbooks.Open(EigDat & "\MMSBest.xls")
xlBlatt = xlMappe.Worksheets(1)
xlZelle = xlBlatt.Range("A1")
intZeilen = xlZelle.CurrentRegion.Rows.Count
xlZelle.Offset(intZeilen, 0).Value = intZeilen
xlZelle.Offset(intZeilen, 1).Value = Now()

'Here's the problem, isn't it?
xlZelle.Offset(intZeilen, 2).Value = Wert
xlMappe.Save()
xlMappe.Close()
xlApp.Quit()

End Sub

Everything works fine, except that at the end my cell contains:
"0" instead of "01234"

I tried:
xlZelle.Offset(intZeilen, 2).Value = CStr(Wert)

But it won't compile. It tells me can't convert one diemnsional array
to string.
Is there any other function I could use?
Or Do I have to:

visual basic code:

Dim strHelp As String
For i = 0 to MyArray.Length - 1
strHelp = strHelp + MyArray(i)
End if

Would this work?
Any better solution?

Nov 21 '05 #4
MIKQ,

I understand now that it is about wert() what is an array of integers.

And you want to do something as
\\\\
dim strHelp as new system.text.stringbuilder
For i = 0 to Wert.Length - 1
strHelp.append(Wert(i).ToString)
End if
xlZelle.Offset(intZeilen, 2).Value = strHelp.ToString
////

Do I understand you right?

Cor


Nov 21 '05 #5
Q
Dear Cor Ligthert,

well my initial question was if there isn't some method (e.g. CStr or
ToString) in the .Net framwork I could use to fill my cell with my array
(integer) (Wert) values.

It seems there isn't, so I have to do a "For i = 0 to Wert.Length - 1"
Loop.
I think I do not understand the whole concept.
Having done only a few VB6 programm, I never heard of
"system.text.stringbuilder"
I'll try the code you provided and read about
"system.text.stringbuilder" in MSDN help.
Any additional information is very welcome.

MIKQ

--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com
Nov 21 '05 #6
> Dear Cor Ligthert,

well my initial question was if there isn't some method (e.g. CStr or
ToString) in the .Net framwork I could use to fill my cell with my array
(integer) (Wert) values.

It seems there isn't, so I have to do a "For i = 0 to Wert.Length - 1"
Loop.
I think I do not understand the whole concept.
Having done only a few VB6 programm, I never heard of
"system.text.stringbuilder"
I'll try the code you provided and read about
"system.text.stringbuilder" in MSDN help.
Any additional information is very welcome.

MIKQ

Mike,

In your case it is not so important if you use stringbuilder.
What is happening is that concatenating strings is expensive for memory use
in VBNet.

Everytime a string is build new and the old one stays in memory until the
Garbage Collector releases it.

To overcome that is stringbuilder. It is not really important in your case.
However writing it as I did was less work to do and absolute not worse than
concatinating.

Cor
Nov 21 '05 #7
Q
Cor,

got it.
Now I understand.
The code you provided works fine too, so I guess my question is
answered.
How is the policy here, any [RESOLVED] I have to add somewhere?

Greetings
MIKQ

--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com
Nov 21 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Andrew V. Romero | last post by:
At work we have an excel file that contains the list of medications and their corresponding strengths. I would like to save the excel file as a text list and paste this list into a javascript...
2
by: Ben Katz | last post by:
Is it possible to have a JavaScript object that works just like a standard Array, except that when the array is modified, a function gets called which can then do some processing on the array? ...
1
by: Ben Katz | last post by:
Is it possible to have an Array object (or an object derived from Array) that is 'aware' of other code modifying its contents? I'd like to have such an "onModify" function process an array...
1
by: Marcel | last post by:
Es soll aus einem Access 2002 AddIn (VBA) heraus eine Excel-Datei geöffnet und möglichst direkt gedruckt werden. Der Dateiname der Excel-Datei ist bekannt. Zuvor oder dabei, sollen VBA-Daten in...
2
by: amir | last post by:
Hallo liebe Gemeinde, ich möchte aus einem Formular aus, eine bereits vorhandene Laufendenummer aus einer Tabelle.spalte auslese und dazu noch eine 1 addiere und dann das Ergebnis in ein...
1
by: Thomas Tawarritsch | last post by:
Hallo, ich muss eine Access200-DB in eine andere Sprache übersetzen. Die Idee ist, mit einer Schleife alle Formulare und Berichte durchlaufen zu lassen und die Capture-Eigenschaft in eine...
2
by: George | last post by:
Is there a fast way to transfer an Excel range to an array? Example: Excel range is E2:E300 Dim person() as string Thanks, George
3
by: George | last post by:
Sub ExcelToListBox() Dim xRange As Object Dim ary Dim xValue As String xRange = oXL.Range("A1:A9") 'has letters A-H ary = xRange.value xValue = ary(3, 1) 'xValue = C...
0
by: blainegray | last post by:
Greetings This is one of those Access is not closing Excel problems. The first time through the code works fine. The second time there is a problem. After lots of combinations, I finally...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.