473,408 Members | 2,477 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,408 software developers and data experts.

How to Export Excel Data to Textfile in a special format?

Hi,

I am trying to export excel data to text file in a particular format.
The Format for each ROW of Excel is like

IMAN_ROOT/bin/import_file -f=<Column A> -type=<Column B> -d=<Column C> -ref=<Column D> -vb -log=<Column E>


Every Row of the excel should export in text with this format.

I have been able to export all the cell values for each row but not in this format.

Should i use delimiter for each cell value for each row.
Any help would be highly appreciated.

this is my code for exporting
Expand|Select|Wrap|Line Numbers
  1. Public Sub ExportToTextFile(FName As String, SelectionOnly As Boolean, AppendData As Boolean)
  2.  
  3. Dim WholeLine As String
  4. Dim FNum As Integer
  5. Dim RowNdx As Long
  6. Dim ColNdx As Integer
  7. Dim StartRow As Long
  8. Dim EndRow As Long
  9. Dim StartCol As Integer
  10. Dim EndCol As Integer
  11. Dim CellValue As String
  12.  
  13.  
  14. Application.ScreenUpdating = False
  15. On Error GoTo EndMacro:
  16. FNum = FreeFile
  17.  
  18. If SelectionOnly = True Then
  19.     With Selection
  20.         StartRow = .Cells(1).Row
  21.         StartCol = .Cells(1).Column
  22.         EndRow = .Cells(.Cells.Count).End(xlUp).Row
  23.         EndCol = .Cells(.Cells.Count).Column
  24.     End With
  25. Else
  26.     With ActiveSheet.UsedRange
  27.         StartRow = 4
  28.         StartCol = .Cells(1).Column
  29.         EndRow = Cells(50000, "A").End(xlUp).Row
  30.         EndCol = .Cells(.Cells.Count).Column
  31.     End With
  32. End If
  33.  
  34. If AppendData = True Then
  35.     Open FName For Append Access Write As #FNum
  36. Else
  37.     Open FName For Output Access Write As #FNum
  38. End If
  39.  
  40. For RowNdx = StartRow To EndRow
  41.     WholeLine = ""
  42.     For ColNdx = StartCol To EndCol
  43.         If Cells(RowNdx, ColNdx).Value = "" Then
  44.             CellValue = Chr(34) & Chr(34)
  45.         Else
  46.            CellValue = Cells(RowNdx, ColNdx).Value
  47.         End If
  48.         WholeLine = WholeLine & CellValue & ","
  49.     Next ColNdx
  50.     WholeLine = Left(WholeLine, Len(WholeLine) - Len(","))
  51.     Print #FNum, WholeLine
  52. Next RowNdx
  53.  
  54. EndMacro:
  55. On Error GoTo 0
  56. Application.ScreenUpdating = True
  57. Close #FNum
  58.  
  59. End Sub
  60.  
  61.  
Jul 22 '10 #1
3 4043
NeoPa
32,556 Expert Mod 16PB
prashantdixit: IMAN_ROOT/bin/import_file -f=<Column A> -type=<Column B> -d=<Column C> -ref=<Column D> -vb -log=<Column E>
I have no idea what this is supposed to be describing. Perhaps some example data formatted as you expect it might help.
Jul 22 '10 #2
I have an Excel Worksheet which has 6 Columns
Column A, Column B, Column C, Column D, Column E, Column F.

Now All these Column contain data.
I have got Export Button on the Excel sheet.
1. When user clicks on Export Button then Dialog box open to Save Excel Data in textfile(.txt format only)
2. Let say i have 1000 rows of data corresponding to each column.
3. So in each line of text file , Data from EACH ROW should get exported in this format.
For Row 1
IMAN_ROOT/bin/import_file -f=<Cells(1,"A")> -type=<Cells(1,"C")> -d=<Cells(1,"D")> -ref=<Cells(1,"E")> -vb -log=<Cells(1,"F")>

Where
<Cells(1, "A")> is Cell value in First Row corresponding to Column A,

<Cells(1, "C")> is Cell value in First Row corresponding to Column C.

PS:
1. I need to values corresponding to Skip Column B for all rows as it is not being used in Format while exporting it to Text file
2. This Text format is basically used to generate a script based on Excel data.

I hope this will help you understanding the problem.
The code has already been posted above through which I have been able to export all the cell values for each row but not in this format.
Jul 22 '10 #3
NeoPa
32,556 Expert Mod 16PB
NeoPa: Perhaps some example data formatted as you expect it might help.
You don't have to pay any attention to what I suggest, but I can't help thinking it would be sensible.
Jul 22 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Vanessa | last post by:
I need to read/extract data from an Excel file using ASP. However, the Excel file is not in regular tabular format; instead, it is actually a form. Therefore, it contains many checkbox and merged...
1
by: Odd Bjørn Andersen | last post by:
When exporting character data with column length greater than 254, the data is truncated. For some reason I have to export the data in DEL format. Is there a way to avoid the truncation of data ? ...
3
by: Mads Petersen | last post by:
I'm stuck in this code. Hope you can and will help me. I launch it from excel. I have made the following code work, but not as i whant. I need the ranges to be working with something like xlDown....
10
by: Niklas | last post by:
Hi Before I start coding I need to be sure that nobody else has not done it yet and that I can use it. I need an import utility which import data from Excel to a database or some object in...
0
by: vbvr | last post by:
I need to export a numeric field (TAX ID) from vb.net to Excel. The value gets converted to Numeric in Excel and leading zeroes are lost. I tried to use code posted on this site. But the style...
1
by: panku007 | last post by:
hi All, I wanted to export excel data into ms word document through java coding.So please send me reply,according to my question. thanks
1
by: san1014 | last post by:
Hi How to import and export excel data into oracle database using java. Thank you
2
by: farukcse | last post by:
Dear Sir, I have a PHP script that export CSV with arabic text, for example I download the CSV on the website then save to desktop of my computer and Open it on NOTEPAD... that works fine I could...
5
by: shigehiro | last post by:
Hi all, I tried to export the data into .csv format.. and the below is how I do it: container.REQUEST.RESPONSE.setHeader('Content-Type','text/csv')...
7
by: beulajo | last post by:
Hai. I have student marks in excel sheet. I need to export this data in to msaccess. I have no problem in exporting the data. My excel sheet is in this format I have 40 students. Each student had...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.