Overview
Import a timestamp from Microsoft Excel into LabVIEW and convert it to the timestamp data.
Description
Simple solution for old problem of converting MS Excel time to LabVIEW time. No more day counting and daylight saving... well let's hope
Concept:
- Get Excel Application refnum
- Open Excel Application
- Get Active Workbook
- Get Active Worksheet
- Select Row (A1)
- Get selected cell current number formatting
- Write or Read cell's value
- Close references
NumberFormatLocal property is used to allow mixed setting for Excel spreadsheets.
Write function:
- Convert LabVIEW timestamp to "m/d/yyyy h:mm:ss" format
- Pass string to Value2 property
Read function:
- Set current cell number format to "m/d/yyyy h:mm:ss"
- Read text property
- Set current cell number format back to original
- Convert text to LabVIEW timestamp
- Close references
Steps to Implement or Execute Code
- Open attached Excel document
- Load Excel Date.vi
- Run VI
Note: Text property only works on single cell's; i.e. cannot be acquired as array. Column or row of timestamps must be read one by one.
Requirements
LabVIEW 2012 (or compatible)
Updates
11/15/2010
Bug: AM/PM switch was missed in original code.
Note: Required testing with 24h style and regional settings other than US.
12/10/2010
Bug: If Excel's Cell is not wide enough to accommodate entire Date and Time string, then reported value from "Text" property would be presented as "####", resulting in string scan error.
Fix: Execute "ShrinkToFit" command before "Text".
04/25/2010
Bug: Error converting time
Fix: Format to LabVIEW timestamp directly
**This document has been updated to meet the current required format for the NI Code Exchange. For more details visit this discussion thread.**