Mercurial > hg > ltpda
comparison m-toolbox/classes/@repogui/createTable.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 function [mtable, buttons] = createTable(pnContainer,headers,data,buttonsFlag,varargin) | |
2 % createTable - create nice-looking table based on javax.swing.JTable | |
3 % | |
4 % Syntax: | |
5 % [mtable, buttons] = createTable (pnContainer, headers, data, buttonsFlag, 'PropName',PropValue, ...) | |
6 % | |
7 % Input Parameters: | |
8 % pnContainer - optional handle to container uipanel or figure. If empty/unsupplied then current figure will be used | |
9 % headers - optional cell array of column header strings. If unsupplied then = {'A','B','C'} | |
10 % data - optional vector/matrix (either scalar or cell array) of data values | |
11 % buttonsFlag - optional flag indicating whether to create the table-manipulation buttons. Default = true | |
12 % 'PropName',PropValue - | |
13 % optional list of property pairs (e.g., 'AutoResizeMode',4,'Editable',false,'Position',[.1,.1,.5,.5]) | |
14 % Note: PropName must be either an mtable property ('Visible','Editable','Position','Units', | |
15 % 'DataChangedCallback',...) or otherwise a Javax.swing.JTable property ('ShowGrid','Name',...). | |
16 % Abbreviated PropNames are unsupported for mtable properties (which are few) - only for JTable | |
17 % | |
18 % Output parameters: | |
19 % mtable - handle to mtable object (a Matlab object) | |
20 % buttons - handles to table manipulation buttons: [<appendRow> <insertRow> <deleteRow> <deleteAll> <printAll>] | |
21 % | |
22 % Examples: | |
23 % [mtable, buttons] = createTable; | |
24 % [mtable, buttons] = createTable(gcf,'column name'); | |
25 % mtable = createTable([],{'a','b','c','d'},{false,1.3,uint16(45),'ert'; true,pi,uint16(-4),'defrgt'}) | |
26 % mtable = createTable([],{'a','b','c','d'},magic(4),false,'AutoResizeMode',javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS) | |
27 % mtable = createTable([],{'rads','sin','cos'},[pi,sin(pi),cos(pi)],'SelectionMode',javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION) | |
28 % | |
29 % Usage: | |
30 % The table automatically resizes to fill the pnContainer (you may modify this via the 'Position' property). | |
31 % The table automatically sets the columns' cell editor and renderer based on the supplied data. Logical values are | |
32 % given a checkbox, strings are left-aligned (numbers are right-aligned). You can always override the defaults. | |
33 % You can change column widths by dragging the column borders on the header row. | |
34 % You can sort columns by clicking the column header (once to sort descending, once again to sort ascending and once | |
35 % more for the unsorted view). Sorting multiple columns is done by control-clicking all relevant columns (the | |
36 % sorting icon is decreased in size for each additional minor sort col). | |
37 % You can copy/paste any consecutive region of table cells, just as in Excel. You can select entire rows or columns | |
38 % by right-clicking their header. You can also paste Excel data directly, with Ctrl-Shift-V (or use the context | |
39 % menu by right-clicking) at the target table cell. | |
40 % For additional tips about how to set multiple aspects of the table, refer to: | |
41 % <a href="http://java.sun.com/docs/books/tutorial/uiswing/components/table.html">http://java.sun.com/docs/books/tutorial/uiswing/components/table.html</a> | |
42 % | |
43 % Programming tips/cues/examples: | |
44 % mtable = creatTable(...) | |
45 % jtable = mtable.getTable; | |
46 % mtable.setVisible(false); | |
47 % mtable.setCheckBoxEditor(1); % Set first column to a checkbox (see Note 2 below) | |
48 % cb = javax.swing.JComboBox({'First','Last'}); cb.setEditable(true); % prepare an editable drop-down CellEditor | |
49 % editor = javax.swing.DefaultCellEditor(cb); | |
50 % jtable.getColumnModel.getColumn(1).setCellEditor(editor); % assign this editor to second column (see Note 2) | |
51 % jtable.getColumnModel.getColumn(0).setMaxWidth(20); % Limit width of first (checkbox) column (see Note 2) | |
52 % mtable.setEditable(0,false); % Disable editing first column (see note 2 below) | |
53 % renderer = javax.swing.table.DefaultTableCellRenderer; % or: renderer = jtable.getColumnModel.getColumn(1).getCellRenderer | |
54 % renderer.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); % useful for numbers rendered as strings e.g.: jtable.setValueAt(sprintf('%.1f',pi,rowIdx,colIdx)) | |
55 % jtable.getColumnModel.getColumn(1).setCellRenderer(renderer); % right-align second column (see note 2) | |
56 % data = cell(mtable.getData); % a cell matrix (mtable.getData is a java.lang.Object[][] object, using base-1 indexing) | |
57 % data = mtable.getTableModel.getDataVector; % a java.util.Vector object ([[false, 1.3, 45, ert], [true, 3.14,...]]) | |
58 % jtable.setValueAt(value,rowIdx,colIdx); % 0-based Idx - see Note 2 below | |
59 % jtable.getModel.addRow({true, pi, int16(45), 'test'}); % appends a row to the bottom of the table | |
60 % mtable.DataChangedCallback = []; % used to temporarily disable data-change callbacks | |
61 % mtable.DataChangedCallback = @myDataChange_Callback; % myDataChange_Callback is a Matlab function | |
62 % | |
63 % % Sample dataChange_Callback function | |
64 % function dataChange_Callback(mtable, eventdata) | |
65 % if ~ishandle(mtable), return; end | |
66 % % Prevent re-entry here if the callback is not thread-safe - see Note 3 below | |
67 % eventDetails = eventdata.getEvent; | |
68 % modifiedColIdx = eventDetails.getColumn; | |
69 % modifiedRowIdx = eventDetails.getFirstRow; | |
70 % if modifiedColIdx>=0 && modifiedRowIdx>=0 | |
71 % data = mtable.getData; | |
72 % newValue = data(modifiedRowIdx+1,modifiedColIdx+1); % see Note 2 below | |
73 % switch modifiedColIdx | |
74 % case ... | |
75 % end | |
76 % end | |
77 % | |
78 % Notes: | |
79 % 1. Some (very few) JTable features are inconsistent or unavailable in different jave versions. Type | |
80 % '<a href="matlab:version -java">version -java</a>' at the command prompt to see your specific java version. | |
81 % 2. Note that java uses 0-based indexing, while Matlab is 1-based. The returned mtable parameter is a Matlab object | |
82 % (so use 1-base), while mtable.getXXX returns java objects (0-based). jtable above is an example of a java object. | |
83 % 3. Modifying mtable.DataChangedCallback within the callback doesn't work - you need to use some global flag/mutex | |
84 % 4. The <Print> button uses Excel to parse and print the table | |
85 % 5. Due to Matlab limitations (specifically, of uitable/UitablePeer) the table is created as a direct child of | |
86 % the container figure (although it is visually positioned within pnContainer) | |
87 % 6. To enable sorting functionality, the attached TableSorter.jar file must be located in the java classpath. | |
88 % See the Matlab documentation for <a href="matlab:doc javaclasspath">javaclasspath</a>. Note that using | |
89 % javaaddpath(...) to set the path has a nasty side-effect (at least since Matlab 7.2) of clearing all globals! | |
90 % An alternative is to place the pathname for TableSorter.jar in the <a href="matlab:which classpath.txt">classpath.txt</a> file | |
91 % | |
92 % Known issues/limitations: | |
93 % - Column alignment not preserved during Print | |
94 % - Print fails if Excel unavailable (maybe directly print tab-separated text data) | |
95 % - Unable to add/delete rows or to print via context menu (right-click) | |
96 % - Table is created as a direct child of figure, not pnContainer (see Note 5 above) | |
97 % | |
98 % Bugs and suggestions: | |
99 % Please send to Yair Altman (altmany at gmail dot com) | |
100 % | |
101 % See also: | |
102 % uitable, java, javaclasspath | |
103 % | |
104 % Release history: | |
105 % 1.0 2007-03-09: initial version | |
106 % 1.1 2007-03-22: fixed selected row# on deletion of bottom row, main comment, missing option; added header tooltip | |
107 % | |
108 % | |
109 % 25-02-08 Adapted and imported into LTPDA | |
110 % M Hewitson | |
111 % | |
112 % $Id: createTable.m,v 1.1 2009/02/03 08:15:30 hewitson Exp $ | |
113 % | |
114 % | |
115 | |
116 % License to use and modify this code is granted freely to all interested, as long as the original author is | |
117 % referenced and attributed as such. The original author maintains the right to be solely associated with this work. | |
118 | |
119 % Programmed and Copyright by Yair M. Altman: altmany(at)gmail.com | |
120 % $Revision: 1.1 $ $Date: 2009/02/03 08:15:30 $ | |
121 | |
122 %try | |
123 % Ensure that java swing is enabled... | |
124 if ~usejava('swing') | |
125 error('createTable:NeedSwing','Java tables require Java Swing.'); | |
126 end | |
127 | |
128 % Create a panel spanning entire figure area, if panel handle was not supplied | |
129 if (nargin < 1) || isempty(pnContainer) || ~ishandle(pnContainer) | |
130 pnContainer = uipanel('parent',gcf,'tag','TablePanel'); | |
131 end | |
132 pnContainerPos = getpixelposition(pnContainer,1); | |
133 if isa(handle(pnContainer), 'figure') | |
134 pnContainerPos(1:2) = 0; | |
135 end | |
136 | |
137 % Get handle to parent figure | |
138 hFig = ancestor(pnContainer,'figure'); | |
139 | |
140 % Determine whether table manipulation buttons are requested | |
141 if nargin < 4 || isempty(buttonsFlag) || ~(isnumeric(buttonsFlag) || islogical(buttonsFlag)) | |
142 if nargin >= 4, varargin = {buttonsFlag, varargin{:}}; end | |
143 buttonsFlag = true; | |
144 end | |
145 if buttonsFlag | |
146 margins = [1,30,0,-30]; % With buttons | |
147 else | |
148 margins = [1,1,0,0]; % No buttons | |
149 end | |
150 | |
151 % Get the uitable's required position within pnContainer | |
152 tablePosition = pnContainerPos + margins; % Relative to the figure | |
153 | |
154 % Set default header names, if not supplied | |
155 if nargin < 2 | |
156 headers = {'A','B','C'}; % 3 columns by default | |
157 elseif isempty(headers) | |
158 headers = cell(1,size(data,2)); | |
159 elseif ischar(headers) | |
160 headers = {headers}; | |
161 end | |
162 | |
163 % Start with dummy data, just so that uitable can be initialized (or use supplied data, if available) | |
164 if nargin < 3 || isempty(data) | |
165 numRows = 0; | |
166 numCols = length(headers); | |
167 data = zeros(1,numCols); | |
168 else | |
169 numRows = size(data,1); | |
170 numCols = size(data,2); | |
171 end | |
172 % Convert to cell-format (if not so already) | |
173 if ~iscell(data) | |
174 data = mat2cell(data,ones(1,size(data,1)),ones(1,numCols)); | |
175 end | |
176 | |
177 % Create a sortable uitable within pnHandle | |
178 mtable = uitable(hFig, 'position',tablePosition, 'Data',data, 'ColumnNames',headers); | |
179 mtable.setNumRows(numRows); | |
180 set(mtable,'units','normalized'); % this will resize the table whenever its container is resized | |
181 | |
182 % jtable is the underlying java JTable - access to lots more functionality... | |
183 % Note: actually, jtable is a com.mathworks.hg.peer.UitablePeer$PeerSpreadsheetTable object, but this extends | |
184 % ^^^^ javax.swing.JTable, so for all practical purposes you may use it as a JTable | |
185 jtable = mtable.getTable; | |
186 | |
187 % Fix for JTable focus bug : see http://bugs.sun.com/bugdatabase/view_bug.do;:WuuT?bug_id=4709394 | |
188 % Taken from: http://xtargets.com/snippets/posts/show/37 | |
189 jtable.putClientProperty('terminateEditOnFocusLost', java.lang.Boolean.TRUE); | |
190 | |
191 % We want to use sorter, not data model... | |
192 % unfortunately, UitablePeer expects DefaultTableModel (not TableSorter) so we need a modified UitablePeer class | |
193 % however, UitablePeer is a Matlab class, so instead let's use a modified TableSorter and attach it to the Model | |
194 %sorter = com.mathworks.toolbox.dasstudio.util.TableSorter; % Failed attempt... | |
195 %sorter = com.mathworks.mwswing.DefaultSortableTable; % ...another failed attempt... | |
196 if ~isempty(which('TableSorter')) | |
197 % Add TableSorter as TableModel listener | |
198 sorter = TableSorter(jtable.getModel()); %(table.getTableModel); | |
199 %tablePeer = UitablePeer(sorter); % This is not accepted by UitablePeer... - see comment above | |
200 jtable.setModel(sorter); | |
201 sorter.setTableHeader(jtable.getTableHeader()); | |
202 | |
203 % Set the header tooltip (with sorting instructions) | |
204 jtable.getTableHeader.setToolTipText('<html> <b>Click</b> to sort up; <b>Shift-click</b> to sort down<br> <b>Ctrl-click</b> (or <b>Ctrl-Shift-click</b>) to sort secondary <br> <b>Click again</b> to change sort direction<br> <b>Click a third time</b> to return to unsorted view<br> <b>Right-click</b> to select entire column</html>'); | |
205 else | |
206 % Set the header tooltip (no sorting instructions...) | |
207 jtable.getTableHeader.setToolTipText('<html> <b>Click</b> to select entire column<br> <b>Ctrl-click</b> (or <b>Shift-click</b>) to select multiple columns </html>'); | |
208 end | |
209 | |
210 % Store the uitable's handle within the pnContainer's userdata, for later use | |
211 set(pnContainer,'userdata',[get(pnContainer,'userdata'), mtable]); % add to parent userdata, so we have a handle for deletion | |
212 | |
213 % Enable multiple row selection, auto-column resize, and auto-scrollbars | |
214 scroll = mtable.TableScrollPane; | |
215 scroll.setVerticalScrollBarPolicy(scroll.VERTICAL_SCROLLBAR_AS_NEEDED); | |
216 scroll.setHorizontalScrollBarPolicy(scroll.HORIZONTAL_SCROLLBAR_AS_NEEDED); | |
217 jtable.setSelectionMode(javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); | |
218 jtable.setAutoResizeMode(jtable.AUTO_RESIZE_SUBSEQUENT_COLUMNS) | |
219 | |
220 % Set the jtable name based on the containing panel's tag | |
221 basicTagName = get(pnContainer,'tag'); | |
222 jtable.setName([basicTagName 'Table']); | |
223 | |
224 % Move the selection to first table cell (if any data available) | |
225 if (jtable.getRowCount > 0) | |
226 jtable.changeSelection(0,0,false,false); | |
227 end | |
228 | |
229 % Process optional args | |
230 for argIdx = 1 : 2 : length(varargin) | |
231 if argIdx<2 | |
232 % We need this pause to let java complete all table rendering | |
233 % TODO: We should really use calls to awtinvoke() instead, though... | |
234 pause(0.05); | |
235 end | |
236 if (length(varargin) > argIdx) % ensure the arg value is there... | |
237 varargin{argIdx}(1) = upper(varargin{argIdx}(1)); % property names always start with capital letters... | |
238 propMethodName = ['set' varargin{argIdx}]; | |
239 if ismethod(mtable,propMethodName) | |
240 set(mtable,varargin{argIdx},varargin{argIdx+1}); | |
241 else | |
242 %javaMethod(propMethodName, jtable, varargin{argIdx+1}); | |
243 set(jtable,varargin{argIdx},varargin{argIdx+1}); | |
244 end | |
245 end | |
246 end % for argIdx | |
247 | |
248 % Create table manipulation buttons | |
249 if buttonsFlag | |
250 buttons = createManipulationButtons(pnContainer,mtable); | |
251 else | |
252 buttons = []; | |
253 end | |
254 %catch | |
255 % Insert your code here | |
256 %handleError; | |
257 %end | |
258 | |
259 | |
260 %% --- Executes on button press in btInsert. | |
261 function buttons = createManipulationButtons(pnContainer, mtable) | |
262 % pnContainer handle to container uipanel | |
263 % mtable handle to mtable (Matlab) object | |
264 %try | |
265 btAppendRow = uicontrol('tag','btTableAppendRow', 'callback',@btTableAppendRow_Callback, 'position', [10,5,60,20], 'string','Append', 'parent',pnContainer, 'userdata',mtable); | |
266 btInsertRow = uicontrol('tag','btTableInsertRow', 'callback',@btTableInsertRow_Callback, 'position', [80,5,60,20], 'string','Insert', 'parent',pnContainer, 'userdata',mtable); | |
267 btDeleteRow = uicontrol('tag','btTableDeleteRow', 'callback',@btTableDeleteRow_Callback, 'position', [150,5,60,20], 'string','Delete', 'parent',pnContainer, 'userdata',mtable); | |
268 btDeleteAll = uicontrol('tag','btTableDeleteAll', 'callback',@btTableDeleteAll_Callback, 'position', [220,5,60,20], 'string','Delete All', 'parent',pnContainer, 'userdata',mtable); | |
269 btPrintAll = uicontrol('tag','btTablePrintAll', 'callback',@btTablePrintAll_Callback, 'position', [290,5,60,20], 'string','Print', 'parent',pnContainer, 'userdata',mtable); | |
270 buttons = [btInsertRow btAppendRow btDeleteRow btDeleteAll btPrintAll]; | |
271 if mtable.getNumRows < 1 | |
272 setVisibility(pnContainer, 'off'); | |
273 end | |
274 %catch | |
275 % Insert your code here | |
276 %handleError; | |
277 %end | |
278 | |
279 | |
280 %% --- Executes on button press in btInsert. | |
281 % Insert a new row immediately before the current row | |
282 function btTableInsertRow_Callback(hObject, eventdata, handles) %#ok | |
283 % hObject handle to btTableInsertRow (see GCBO) | |
284 % eventdata reserved - to be defined in a future version of MATLAB | |
285 % handles structure with handles and user data (see GUIDATA) | |
286 %try | |
287 mtable = get(hObject,'userdata'); | |
288 jtable = mtable.getTable; | |
289 | |
290 % Stop any current editing | |
291 stopEditing(jtable); | |
292 | |
293 % Insert the new row immediately before the current row | |
294 newRowData = cell(1,mtable.getNumColumns); % empty data | |
295 mtable.getTableModel.insertRow(max(0,jtable.getSelectedRow), newRowData); | |
296 %catch | |
297 % Insert your code here | |
298 %handleError; | |
299 %end | |
300 | |
301 | |
302 %% --- Executes on button press in btAppend. | |
303 % Insert a new row as the last row in the table | |
304 function btTableAppendRow_Callback(hObject, eventdata, handles) %#ok | |
305 % hObject handle to btTableAppendRow (see GCBO) | |
306 % eventdata reserved - to be defined in a future version of MATLAB | |
307 % handles structure with handles and user data (see GUIDATA) | |
308 %try | |
309 mtable = get(hObject,'userdata'); | |
310 jtable = mtable.getTable; | |
311 | |
312 % Stop any current editing | |
313 stopEditing(jtable); | |
314 | |
315 % Add a new row at the bottom of the data table | |
316 newRowData = cell(1,mtable.getNumColumns); % empty data | |
317 mtable.getTableModel.addRow(newRowData); | |
318 | |
319 % Move the selection to Column A of this new row | |
320 jtable.changeSelection(jtable.getRowCount-1,0,false,false); | |
321 | |
322 % There must be at least one table row now, so display the table in any case | |
323 mtable.setVisible(true); | |
324 setVisibility(hObject, 'on'); | |
325 %catch | |
326 % Insert your code here | |
327 %handleError; | |
328 %end | |
329 | |
330 | |
331 %% --- Executes on button press in btDelete. | |
332 % If there are any rows displayed, then delete the currently-selected row | |
333 function btTableDeleteRow_Callback(hObject, eventdata, handles) %#ok | |
334 % hObject handle to btTableDeleteRow (see GCBO) | |
335 % eventdata reserved - to be defined in a future version of MATLAB | |
336 % handles structure with handles and user data (see GUIDATA) | |
337 %try | |
338 mtable = get(hObject,'userdata'); | |
339 jtable = mtable.getTable; | |
340 | |
341 % Stop any current editing | |
342 stopEditing(jtable); | |
343 | |
344 % If there are any rows displayed, then delete the currently-selected row | |
345 rowCount = jtable.getRowCount; | |
346 if (rowCount > 0) % might be==0 during slow processing & user double-click | |
347 currentRow = max(0,jtable.getSelectedRow); | |
348 currentCol = max(0,jtable.getSelectedColumn); | |
349 mtable.getTableModel.removeRow(currentRow); | |
350 if currentRow >= rowCount-1 | |
351 jtable.changeSelection(currentRow-1, currentCol, false, false); | |
352 end | |
353 end | |
354 if (jtable.getRowCount <= 0) | |
355 %table.setVisible(false); | |
356 setVisibility(hObject, 'off'); | |
357 end | |
358 %catch | |
359 % Insert your code here | |
360 %handleError; | |
361 %end | |
362 | |
363 | |
364 %% --- Executes on button press in btDeleteAll. | |
365 % Deletes all table rows | |
366 function btTableDeleteAll_Callback(hObject, eventdata, handles) %#ok | |
367 % hObject handle to btTableDeleteAll (see GCBO) | |
368 % eventdata reserved - to be defined in a future version of MATLAB | |
369 % handles structure with handles and user data (see GUIDATA) | |
370 %try | |
371 mtable = get(hObject,'userdata'); | |
372 jtable = mtable.getTable; | |
373 | |
374 % Stop any current editing | |
375 stopEditing(jtable); | |
376 | |
377 % Delete all table rows | |
378 mtable.setNumRows(0); | |
379 | |
380 % Hide irrelevant controls | |
381 %mtable.setVisible(false); | |
382 setVisibility(hObject, 'off'); | |
383 %catch | |
384 % Insert your code here | |
385 %handleError; | |
386 %end | |
387 | |
388 | |
389 %% --- Executes on button press in btPrint. | |
390 % Prints the table via Excel | |
391 function btTablePrintAll_Callback(hObject, eventdata, handles) %#ok | |
392 % hObject handle to btTablePrintAll (see GCBO) | |
393 % eventdata reserved - to be defined in a future version of MATLAB | |
394 % handles structure with handles and user data (see GUIDATA) | |
395 persistent hExcel | |
396 try | |
397 mtable = get(hObject,'userdata'); | |
398 | |
399 % Try to open an Excel COM server | |
400 % Note: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_2003_ta/html/odc_landoffice03_vba.asp | |
401 try | |
402 % try to reuse an existing (pre-opened) COM server | |
403 % If we can't access the ActiveX parent, it means it's closed | |
404 parent = hExcel.parent; %#ok | |
405 catch | |
406 hExcel = actxserver('excel.application'); | |
407 end | |
408 | |
409 % Try to open the requested document | |
410 hExcel.Workbooks.Add; | |
411 | |
412 % Format field headers | |
413 headers = cell(mtable.getColumnNames)'; | |
414 if ~isempty(headers) | |
415 hExcel.Range(['A1:' n2a(length(headers)) '1']).Select; | |
416 hExcel.Selection.Value = headers; | |
417 hExcel.Selection.Font.Bold = true; % bold | |
418 hExcel.Selection.Font.Color = hex2dec('0000FF'); % Red | |
419 hExcel.Selection.Border.Item(4).Weight = 3; % underline | |
420 hExcel.Selection.Cells.HorizontalAlignment = -4108; % =xlCenter | |
421 end | |
422 | |
423 % Set the data from the table | |
424 data = cell(mtable.data); | |
425 if ~isempty(headers) | |
426 hExcel.Range(['A2:' n2a(size(data,2)) num2str(1+size(data,1))]).Select; | |
427 hExcel.Selection.Value = data; | |
428 end | |
429 | |
430 % TODO: Change checkbox fields to boolean (TRUE/empty) | |
431 | |
432 % Other formats | |
433 %hExcel.Cells.HorizontalAlignment = -4108; % =xlCenter % TODO: preserve original jtable column alignment | |
434 hExcel.Cells.EntireColumn.AutoFit; | |
435 hExcel.ActiveSheet.DisplayRightToLeft = false; | |
436 set(hExcel.ActiveSheet.PageSetup, 'LeftMargin', hExcel.InchesToPoints(0.1), ... | |
437 'RightMargin', hExcel.InchesToPoints(0.1), ... | |
438 'HeaderMargin',hExcel.InchesToPoints(0), ... | |
439 'FooterMargin',hExcel.InchesToPoints(0.1), ... | |
440 'TopMargin',120, ... | |
441 'FitToPagesWide',1, ... | |
442 'FitToPagesTall',1, ... | |
443 'Orientation','xlPortrait', ... | |
444 'LeftHeader','&D &T', ... | |
445 'CenterHeader',char(mtable.getTable.getName), ... | |
446 'RightHeader','&G'); | |
447 | |
448 % Send to printer | |
449 hExcel.ActiveWindow.SelectedSheets.PrintOut; | |
450 | |
451 % Close the workbook | |
452 invoke(hExcel.ActiveWindow,'close',false); | |
453 catch | |
454 % Insert your code here | |
455 %handleError; | |
456 err = lasterror; | |
457 try invoke(hExcel.ActiveWindow,'close',false); catch end; % just in case of a printing error | |
458 rethrow(err); | |
459 end | |
460 | |
461 | |
462 %% --- Convert col # format to 'A','B','C','AA',... format | |
463 % Thanks Brett Shoelson, via CSSM | |
464 function colStr = n2a(c) | |
465 t = [floor((c-1)/26)+64, rem(c-1,26)+65]; | |
466 if (t(1)<65), t(1) = []; end | |
467 colStr = char(t); | |
468 | |
469 | |
470 %% --- Executes on button press in btInsert. | |
471 function stopEditing(jtable) | |
472 %try | |
473 component = jtable.getEditorComponent; | |
474 if ~isempty(component) | |
475 event = javax.swing.event.ChangeEvent(component); | |
476 jtable.editingStopped(event); | |
477 end | |
478 %catch | |
479 % Insert your code here | |
480 %handleError; | |
481 %end | |
482 | |
483 | |
484 %% --- Utility function to set visibility of row manipulation buttons | |
485 function setVisibility(hObject, enableStr) | |
486 % hObject handle to some element within the figure | |
487 % enableStr 'on' or 'off' | |
488 %try | |
489 hParent = ancestor(hObject,'figure'); | |
490 set(findall(hParent,'tag','btTableInsertRow'),'enable',enableStr); | |
491 set(findall(hParent,'tag','btTableDeleteRow'),'enable',enableStr); | |
492 set(findall(hParent,'tag','btTableDeleteAll'),'enable',enableStr); | |
493 set(findall(hParent,'tag','btTablePrintAll'), 'enable',enableStr); | |
494 %catch | |
495 % Insert your code here | |
496 %handleError; | |
497 %end |