Code covered by the BSD License  

Highlights from
dat2xls

3.33333

3.3 | 3 ratings Rate this file 7 Downloads (last 30 days) File Size: 3.95 KB File ID: #4517
image thumbnail

dat2xls

by Fahad Al Mahmood

 

22 Feb 2004 (Updated 13 Oct 2004)

Copying (ASCII) data file (including headers & column names) to XLS.

| Watch this File

File Information
Description

This program reads a (text data file) consisting of headers, column titles and column data (see attached data.txt). Then it opens or creates existing excel file and saves data into specified sheetname.

NOTE: The program will automatically identify the number of headerlines, columns and the column names using what so called "common sense"!

dat2xls(datfile,xlsfile,sheetname)
dat2xls(datfile,xlsfile)

datfile: Name of data file.
xlsfile: Name of excel file.
sheetname: sheet name (optional, default is 'Sheet1') if specified, a sheet with the specified name must be existing.

Example:

datfile = 'data.txt';
xlsfile = 'data.xls';
sheetname = 'Sheet2';
dat2xls(datfile,xlsfile,sheetname)
%dat2xls(datfile,xlsfile) % Will write to 'Sheet1'

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
xlswrite
This submission has inspired the following:
Example of how to save or read data to an Excel archive.

MATLAB release MATLAB 7 (R14)
Other requirements Microsoft Excel
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (4)
27 Oct 2004 krishna proddaturi

Text files and xls files with different kinda header and then with actual data this is the one that suits the best use
A=importdata('data.xls');
B=A.data.Sheet1; later to get that acutal data removing all the header info...
This is the best I knew here

28 Nov 2004 bijoy p

i got this error while executing the program

Warning: Reference to uninitialized variable m in dat2xls at line 108.
> In D:\bijoy\matlab\dat2xls.m at line 108
??? Dispatch : Exception occurred.

Error in ==> \\ncc-z\matlab\6.1\toolbox\matlab\winfun\@activex\private\actxcli.dll
Error in ==> \\ncc-z\matlab\6.1\toolbox\matlab\winfun\@activex\get.m
On line 15 ==> varargout{1} = actxcli('get', varargin{1}.Handle,varargin{2:end});

Error in ==> D:\bijoy\matlab\dat2xls.m
On line 155 ==> ActivesheetRange = get(Activesheet,'Range',[FirstCol num2str(FirstRow)],[LastCol num2str(LastRow)]);

08 Mar 2005 alain chuchu  
04 Sep 2006 Ketan D

If there is no header, it gives the following error:

??? Undefined function or variable "header".

Error in ==> dat2xls at 78
for ii=length(header):-1:1

Please login to add a comment or rating.
Updates
27 Feb 2004

Header bug has been fixed.

03 Mar 2004

Another Header bug has been fixed

03 Mar 2004

Saving exisiting file bug has been fixed

04 Mar 2004

For some reason, my update did not go through ... this is another try ...

01 Jun 2004

Updated subfunction (localComputLastCol)

02 Jun 2004

Corrected Screen Output!

07 Jul 2004

Function Renamed

13 Oct 2004

Attached (data.txt)

Tag Activity for this File
Tag Applied By Date/Time
data import Fahad Al Mahmood 22 Oct 2008 07:14:52
data export Fahad Al Mahmood 22 Oct 2008 07:14:52
excel Fahad Al Mahmood 22 Oct 2008 07:14:52
activex Fahad Al Mahmood 22 Oct 2008 07:14:52
txt Fahad Al Mahmood 22 Oct 2008 07:14:52
spreadsheet Fahad Al Mahmood 22 Oct 2008 07:14:52
xls Fahad Al Mahmood 22 Oct 2008 07:14:52

Contact us at files@mathworks.com