Explainer
Why WinCC Unified scripts export tag data as CSV, not Excel
Short answer
A WinCC Unified runtime script cannot write an .xlsx file: its JavaScript environment exposes tags, screen items, alarms and system functions, with no file-system or zip library, and an Excel workbook is a zipped XML package. Log the tags, select a start and end time on a screen, and export that range as CSV from the trend control's export or an external log reader, converting UTC to local time in one place.

On this page
A WinCC Unified runtime script cannot write an Excel workbook, and no function is hiding from you: the runtime's JavaScript environment exposes tags, screen items, alarms and system functions through an object model, and nothing in that model creates files or compresses XML — which is what an .xlsx file is, a zipped package of XML parts. The working pattern is to log the tags, let the operator pick a start and end time on a screen, and deliver that range as CSV, either from the trend control's export or from a small reader outside the HMI. Excel opens the CSV directly, and the script's whole job is to collect and validate two timestamps.
Two different exports share the name #
When an engineer says "export to Excel" in a WinCC Unified project, two unrelated tasks can be meant, and they run in different places.
| Task | Where it runs | What produces the file |
|---|---|---|
| Export screens, tags or texts of the project | The engineering PC, in the TIA Portal project | Engineering tooling, not runtime scripts |
| Export logged process values for a time range | The runtime, on a panel, a PC station or a browser client | The data log plus the trend control's export, or an external reader |
A support entry about automatically creating and exporting HMI screen objects with Excel belongs to the first row: it is engineering automation and never touches live values. A request to export data by date and time is the second row. The engineering route has its own hard limits, and why WinCC Unified screens have no Openness export method covers that side of the fence. Decide which row you are in before writing a line of code, because the tools do not overlap.
Why the script cannot write the workbook #
Runtime scripting in Unified is JavaScript, and the runtime scripting documentation lists the objects that carry scripts. Everything a script does goes through the documented object model: read and write tags, address screen items, work with alarms and system functions, in an object-oriented style. That model contains no general-purpose file creation, no compression library and no Office support.
An .xlsx workbook is not a text file with a different extension. It is a ZIP archive of XML parts with a defined structure, so producing one takes both a ZIP implementation and code that writes those parts in the right order. The runtime ships neither, and a script cannot import them. The boundary is the same one you meet elsewhere: why WinCC Unified scripts cannot launch a batch file is the same sandbox seen from another angle.
CSV has none of these problems. It is plain text with a delimiter and a line break, and Excel opens it. So the decision in front of you is not how to make the script emit a native workbook — it is where the CSV gets produced.
Where the CSV comes from #
Work through three layers, in this order:
- The log comes first. Turn on logging for the tags in the data logging configuration and set the logging cycle or the on-change condition to the resolution the report needs. The export can only contain values that were stored; no export path recovers what was never logged.
- The trend control's export comes second. If the operator needs to view a time range and save it, use the control's export. The documentation is explicit for the trend control: check the time format configured for the control's time axis, because the export file's time axis takes on that format. Set it before anyone relies on the file, and try this path in your version before writing anything custom.
- An external reader comes third. If the file must have a fixed column order, a fixed name or land on a network share, read the log from outside the HMI — the log database or the runtime's external interface — with a small service on the PC, and hand that service the start and end times.
Keep the script thin either way. Pulling thousands of archived values into a script to assemble text is the wrong layer, and script-side reads hit their own ceiling, as why a WinCC Unified V19 script cannot read an HMI array at once shows. The script collects two timestamps, validates them and passes them on.
Building the date and time filter #
Create two tags of a date-time type and bind them to I/O fields on the report screen. The button is among the objects the runtime scripting documentation lists as scriptable, so hang the check on its event script. The check does two things: it refuses an end earlier than the start, and it refuses a span longer than a limit you choose, because an unbounded range can return a very large result and stall the client that requested it.
// Illustrative names chosen for this example. None of these are
// documented WinCC Unified object-model names.
// rangeStart, rangeEnd : Date, read from the two screen I/O fields
// maxSpanMs : Number, the span limit you choose
var rangeStart = new Date("2024-03-10T05:00:00Z"); // example start, UTC
var rangeEnd = new Date("2024-03-10T17:00:00Z"); // example end, UTC
var maxSpanMs = 7 * 24 * 60 * 60 * 1000; // example limit: 7 days
var spanMs = rangeEnd.getTime() - rangeStart.getTime();
if (spanMs <= 0) {
// reject: the end must be later than the start
} else if (spanMs > maxSpanMs) {
// reject: the range is longer than the limit you chose
} else {
// hand rangeStart and rangeEnd on: control time range or handshake tags
}
Prove the branch with the example numbers. 17:00 minus 05:00 is 12 h, and 12 × 3,600,000 = 43,200,000 ms, which does not exceed 7 × 24 × 60 × 60 × 1000 = 604,800,000 ms, so the request passes. Swap the two inputs and spanMs becomes −43,200,000 ms, so the first branch rejects before anything is exported.
Do the first long-range trials on a bench runtime, not on the station an operator is using to run the machine: an export that stalls a client takes the operator's screen with it.
One time base from log to file #
The runtime keeps log timestamps in UTC; the operator types and reads local time; the CSV is expected in local time. That means exactly one conversion between the log and the file, in one component. If the trend control's export produces the file, the conversion point is the control: set the time format of its time axis and let the export carry it. If the PC service produces the file, convert there and leave everything upstream in UTC.
Convert in two places and every timestamp in the file moves by the offset; the mistake is easiest to catch on the daylight-saving date, because the offset itself changes there. A sample stored at 12:00 UTC is 13:00 local for a plant at UTC+1 in winter and 14:00 at UTC+2 in summer.
CSV details Excel cares about #
Three properties decide whether the file opens cleanly on the operator's PC:
- Delimiter. Excel splits a CSV on the list separator configured in the regional settings of the PC that opens the file. A comma-delimited file opened on a PC set to semicolon lands in one column. Write the file with the target PC's separator, or have the service read that setting before it writes.
- Decimal separator. Write numeric values with the decimal separator the target Excel expects, or the numbers arrive as text and every formula downstream breaks.
- Header row. One header row with tag name and unit, and no blank or merged rows above the data, so a straight import lands the columns where they belong.
Checks before you release the export #
Run these once, with a tag you can watch live:
- Row count. Take a tag logged on a 30 s cycle and request a 10-minute window. The window is 600 s, so 600 ÷ 30 = 20 logging intervals, and the file should carry about 20 rows for that tag. Accept 19 to 21: a boundary sample can drop in or out at each edge, depending on where the logging instants fall relative to the requested times.
- Boundaries. The first timestamp must not be earlier than the requested start and the last not later than the requested end.
- A range with logging stopped. Expect a header-only file or a clear message — never a runtime error.
- A reversed range. Expect the script's rejection before any export call; this is the branch proved with the swapped inputs above.
- The operator's PC, not the engineering PC. Expect separate columns, numeric cells right-aligned and timestamps recognized as dates.
- Every client that will run it. Export from the panel and from a browser client and compare the two files; identical content, or the difference points at a client-side path or permission.
Questions asked
Which WinCC Unified objects can carry a JavaScript?
Runtime scripting is supported on screen objects, and the documentation names the rectangle, gauge, button and circle for event scripts. A report screen built from I/O fields and a button therefore has a scriptable trigger: the fields hold the two times, the button's event script reads and checks them. Check the object list for your version before adding scripts to exotic controls.
How many rows will one export contain?
Rows per tag equal the window divided by the logging cycle. At a 30-second cycle, one day is 86,400 divided by 30, so 2,880 rows, and the 7-day example limit is 2,880 times 7, so 20,160 rows per tag. Ten tags at that limit come to about 201,600 rows, which Excel handles but opens slowly; split longer reports into daily files and let the service name them.
Why does the CSV open as a single column on the operator PC?
The decimal separator gives it away: on a PC whose decimal separator is a comma, the list separator is normally a semicolon, so a comma-delimited file opens in one column. Two fixes work: have the writer use the target PC's separator, or import the file through Excel's data import dialog and pick the delimiter there. Opening by double-click never asks.
Can a WinCC Unified runtime produce a real .xlsx file at all?
Not from the runtime; no script, function or workaround turns a Unified panel into a workbook writer. Produce the CSV, then convert outside: open it in Excel and save it as a workbook, or let the PC service that already writes the CSV also write the .xlsx, since a Windows service can use a real spreadsheet library. The runtime script stays what it is good at: validating two timestamps and handing them over.


