|
-
Mar 8th, 2010, 07:17 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Export from Listbox to Excel
I have an app which exports data to Excel. In excel the data is added, but with an square. This makes the calculations in Excel impossible.
I've tried to use the replace in text changed, but with no luck.
The code that export Listbox lines to Excel:
Code:
Dim trace As Integer
For trace = 1 To ListBox1.Items.Count
xlWorkSheet.Cells(trace + 18, 2).Value = ListBox1.Items(trace - 1)
Next
ListBox1_TextChanged:
Code:
ListBox1.Text = Replace(ListBox1.Text, Chr(8), String.Empty) 'backspace
ListBox1.Text = Replace(ListBox1.Text, Chr(9), String.Empty) ' tab
ListBox1.Text = Replace(ListBox1.Text, Chr(10), String.Empty) 'LF
ListBox1.Text = Replace(ListBox1.Text, Chr(11), String.Empty) 'vertical tab
ListBox1.Text = Replace(ListBox1.Text, Chr(12), String.Empty) 'form feed, new page
ListBox1.Text = Replace(ListBox1.Text, Chr(13), String.Empty) 'CR
ListBox1.Text = Replace(ListBox1.Text, Chr(32), String.Empty) 'Space
ListBox1.Text = Replace(ListBox1.Text, Chr(35), String.Empty)
ListBox1.Text = Replace(ListBox1.Text, Chr(127), String.Empty)
ListBox1.Text = Replace(ListBox1.Text, Chr(129), String.Empty)
ListBox1.Text = Replace(ListBox1.Text, Chr(141), String.Empty)
ListBox1.Text = Replace(ListBox1.Text, Chr(143), String.Empty)
ListBox1.Text = Replace(ListBox1.Text, Chr(144), String.Empty)
ListBox1.Text = Replace(ListBox1.Text, Chr(157), String.Empty)
ListBox1.Text = Replace(ListBox1.Text, Chr(249), String.Empty)
ListBox1.Text = Replace(ListBox1.Text, Chr(254), String.Empty) 'Black box
ListBox1.Text = Replace(ListBox1.Text, Chr(255), String.Empty) 'White Space
-
Mar 8th, 2010, 07:47 AM
#2
Re: Export from Listbox to Excel
What happens if you do:
Code:
Dim trace As Integer
For trace = 1 To ListBox1.Items.Count
xlWorkSheet.Cells(trace + 18, 2).FormulaR1C1 = ListBox1.Items(trace - 1).ToString
Next
Also you don't need that code in ListBox1_TextChanged event.
Can you attach a sample file?
-
Mar 8th, 2010, 08:45 AM
#3
Thread Starter
Hyperactive Member
Re: Export from Listbox to Excel
Hi, thanks. The result was the same with your code. The text is pasted into a richtextbox, by the user. So I have no example, but it's just numbers.
I also tried to export from a richtextbox, also with the same result.
Export from textbox code:
Code:
Dim Text As String = String.Empty
Dim i As Integer = 0
Dim Lines As Integer = txtTraceSpeed.Lines.Length
For i = 0 To Lines - 1
Text = txtTraceSpeed.Lines(i).ToString()
xlWorkSheet.Range("B" & i + 1).Value = Text
Next
The square seems to be a tab, but i'm not sure.
-
Mar 8th, 2010, 08:55 AM
#4
Thread Starter
Hyperactive Member
Re: Export from Listbox to Excel
It could be resolved with this:
Code:
lstTraceSpeed.Text = Replace(lstTraceSpeed.Text, Chr(9), String.Empty)
But only for the textbox, this didn't work for the listbox.
-
Mar 8th, 2010, 09:10 AM
#5
Re: [RESOLVED] Export from Listbox to Excel
xlWorkSheet.Cells(trace + 18, 2).Value = ListBox1.Items(trace - 1)
Try triming the value before exporting it to excel...
Edit: I had not refresh the page!!!! Damn
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|