xlswrite
Write Microsoft Excel spreadsheet file.
Syntax
xlswrite(filename,A) xlswrite(filename,A,sheet) xlswrite(filename,A,xlRange) xlswrite(filename,A,sheet,xlRange)
Input Arguments
filename — Name of file to write
string
Name of file to write, specified as a string.
If filename does not exist, xlswrite creates a file, determining the format based on the specified extension. To create a file compatible with Excel 97-2003 software, specify an extension of .xls. To create files in Excel 2007 formats, specify an extension of .xlsx, .xlsb, or .xlsm. If you do not specify an extension, xlswrite uses the default, .xls.
Example: ‘myFile.xlsx’
A — Data to write
matrix | cell array
Data to write, specified as a two-dimensional numeric or character array, or, if each cell contains a single element, a cell array.
If A is a cell array containing something other than a scalar numeric or a string, then xlswrite silently leaves the corresponding cell in the spreadsheet empty.
The maximum size of array A depends on the associated Excel version. For more information on Excel specifications and limits, see the Excel help.
Example: [10,2,45;-32,478,50]
Example: {92.0,’Yes’,45.9,’No’}
Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | char | cell
sheet — Worksheet name
string | positive integer
Worksheet name, specified as one of the following:
String that contains the worksheet name. Cannot contain a colon (:). To determine the names of the sheets in a spreadsheet file, use xlsfinfo.
Positive integer that indicates the worksheet index.
If sheet does not exist, xlswrite adds a new sheet at the end of the worksheet collection. If sheet is an index larger than the number of worksheets, xlswrite appends empty sheets until the number of worksheets in the workbook equals sheet. In either case, xlswrite generates a warning indicating that it has added a new worksheet.
xlRange — Rectangular(方形) portion(部分) of the worksheet to write
string
Rectangular portion of the worksheet to write, specified as a string.
Specify xlRange using the syntax ‘C1:C2’, where C1 and C2 are two opposing corners that define the region to write. For example, ‘D2:H4’ represents the 3-by-5 rectangular region between the two corners D2 and H4 on the worksheet. The xlRange input is not case sensitive, and uses Excel A1 reference style (see Excel help). xlswrite does not recognize named ranges.
If you do not specify sheet, then xlRange must include both corners and a colon character, even for a single cell (such as ‘D2:D2’). Otherwise, xlswrite interprets the input as a worksheet name (such as ‘D2’).
If you specify sheet, then xlRange can specify only the first cell (such as ‘D2’). xlswrite writes input array A beginning at this cell.
If xlRange is larger than the size of input array A, Excel software fills the remainder of the region with #N/A. If xlRange is smaller than the size of A, then xlswrite writes only the subset that fits into xlRange to the file.
Output Arguments
expand all
status — Status of the write operation
1 | 0
Status of the write operation, returned as either 1 (true) or 0 (false). When the write operation is successful, status is 1. Otherwise, status is 0.
message — Error or warning generated during the write operation
structure array
Error or warning generated during the write operation, returned as a structure array containing two fields:
Structure member | Remark |
---|---|
message | Text of the warning or error message, returned as a string. |
identifier | Message identifier, returned as a string. |
附:
向EXCLE追(wnnp)加数据
[num, text, raw] = xlsread(fileName); [rowN, columnN]=size(raw); %worksheet's index sheet=1; xlsRange=['A',num2str(rowN+1)]; xlswrite(fileName,data,sheet,xlsRange);