473,659 Members | 2,640 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

36 New Member
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 4066
NeoPa
32,568 Recognized Expert Moderator MVP
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
prashantdixit
36 New Member
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,568 Recognized Expert Moderator MVP
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
3533
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 cells with data. I have followed this web page's instruction (http://www.haneng.com/Forums_Post.asp?id=4099) to read data out, but whenever the cell has checkbox or it is a merged cell, it can't read the data. Is there anyway to read data...
1
2452
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 ? -- Regards ----------- Odd Bjørn Andersen ErgoSolutions AS
3
25045
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. eg. this only transferes the first record in the area. ..Fields("Uge").Value = ws.Range("A98").Value Sub SelectMaster()
10
11811
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 .NET. The data in Excel is not in structured columns but can exist everywhere in the workbook. For example if I am supposed to import a person and all his/her cars which exist in a workbook I want to be able to create an import protocol and specify...
0
1464
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 defined here does not get applied in Excel. Following is the sample code. Any suggestions on how to keep the text "02345" in the same format in Excel? >>>>>>>>>>>>>>>>>>>> Dim Excel As New Excel.Application Dim wb As Excel.Workbook ...
1
3047
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
2853
by: san1014 | last post by:
Hi How to import and export excel data into oracle database using java. Thank you
2
16529
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 still see all the arabic text OK with no problem, but if I open the CSV file in Microsoft EXCEL, all the arabic text are busted and no longer readable. arabic text is inserted and stored in database as UTF-8 format. Do you know a solution for...
5
4897
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') container.REQUEST.RESPONSE.setHeader('Content-Disposition', 'attachment;filename=outputFile.csv') container.REQUEST.RESPONSE.write(outputString) The above works completely fine when I tested it in Firefox, but when I used IE, it will prompt user to save file as a 'Document' file type (&...
7
2631
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 attended 9 tests which has 5 criteria, under which marks had been given(10). one sample data is B0841 Albert Raja A. 0 0 0 0 0 0 0 0 0 0.5 2 2 0 0 1
0
8428
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8851
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7360
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6181
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4176
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2757
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1982
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.