10 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | ||
|---|---|---|---|---|---|---|
|
2026-04-16T03:37:36.193666+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | 3504eb010d91451f |
XLSX
Documentation: DTS.Serialization.XLSX.File
1. Purpose
This module provides XLSX-specific serialization functionality for Test objects, implementing the abstract Serialization.File base class and the IWritable<Test> interface. Its primary purpose is to export test data (e.g., analog channel measurements) into Excel-compatible .xlsx files using the Open XML SDK. Currently, it supports exporting Engineering Units (EU) by default, with optional controls for exporting raw ADC counts (ExportADC) and millivolt values (ExportMV). The implementation is tightly coupled to the Test model and its channel hierarchy, and it supports both raw and filtered data export based on runtime configuration.
2. Public Interface
public partial class File : Serialization.File, IWritable<Test>
-
public File()
Constructor. Initializes the base class with"XLSX"as the file type identifier. -
public IWriter<Test> Exporter { get; }
Returns the singletonWriterinstance for thisFile. Lazily instantiates aWriteron first access usingDefaultEncoding. Throws anException(wrapping the inner exception) if instantiation fails. -
public bool ExportADC { set; }
Sets theExportADCproperty on the underlyingWriterinstance. Controls whether raw ADC values are exported. -
public bool ExportEU { set; }
Sets theExportEUproperty on the underlyingWriter. Controls whether Engineering Units (EU) are exported (default:true). -
public bool ExportMV { set; }
Sets theExportMvproperty on the underlyingWriter. Controls whether millivolt (mV) values are exported.
Note
: All three export flags (
ExportADC,ExportEU,ExportMV) are setters only onFile. There is no public getter, and the flags are applied only during theWrite(...)call on theWriter.
public class Writer : Writer<File>, IWriter<Test>
-
internal File WriterParent { get; }
Reference to the owningFileinstance. -
public bool ExportADC { get; set; }
Gets/sets whether to export raw ADC values. -
public bool ExportEU { get; set; }
Gets/sets whether to export Engineering Units. -
public bool ExportMv { get; set; }
Gets/sets whether to export millivolt values. -
public double Start { get; set; }
Start time (in seconds) for data slicing. -
public double Stop { get; set; }
Stop time (in seconds) for data slicing. -
public bool Filtered { get; set; }
Iftrue, applies software filtering (viaSaeJ211Filter) to EU data before export. -
public void Write(string pathname, string id, Test test, bool bFiltering, bool includeGroupNameInISOExport, double minStartTime, int dataCollectionLength)
Overload 1 (incomplete implementation) — currently has no body. -
public void Write(string pathname, string id, string dataFolder, Test test, bool bFiltering, bool includeGroupNameInISOExport, FilteredData fd, Test.Module.Channel tmChannel, int channelNumber, BeginEventHandler beginEventHandler, CancelEventHandler cancelEventHandler, EndEventHandler endEventHandler, TickEventHandler tickEventHandler, ErrorEventHandler errorEventHandler, CancelRequested cancelRequested, double minStartTime, int dataCollectionLength)
Overload 2 (full implementation) — writes theTestobject to an.xlsxfile atpathname.- Uses a template file (
XLSXExportTemplate.xlsx) located inReportTemplates. - Writes metadata (inception date/time, test ID, description) to fixed cells in the
"Data"worksheet. - Writes per-channel metadata (sample rate, filter cutoff, units, etc.) to rows 6–23.
- Writes time-series data starting at row 24.
- Applies filtering only if
FilteredistrueandbFilteringistrue. - Uses SAX-style streaming (
OpenXmlReader/OpenXmlWriter) for efficient large-data export. - Fires progress (
tickEventHandler), error (errorEventHandler), and completion (endEventHandler) callbacks. - Clears
RowIndexToRowand_stringLookupcaches before each write. - Forces full recalculation on load (
ForceFullCalculation = true,FullCalculationOnLoad = true). - Adds a date/time number format style (
NumberFormatId = 14) to the stylesheet. - Releases channel data (
UnSet()) and triggers full garbage collection after writing.
- Uses a template file (
-
public void Initialize(...)
Overload — currently has no body. -
private static Common.DAS.Concepts.DataScaler GetDataScaler(Test.Module.AnalogInputChannel)
Constructs and configures aDataScalerinstance from anAnalogInputChannel, including linearization, scaling, zeroing, and excitation parameters. -
protected Cell GetCell(Worksheet worksheet, string xColumn, UInt32 rowIndex, bool bLookForCell = true)
Retrieves or inserts a cell at the given column and row. UsesRowIndexToRowcache for performance. -
private static Cell InsertCellInWorksheet(...)
Inserts a cell into the worksheet, maintaining Open XML cell ordering requirements. -
private void WriteTime(...)/WriteDate(...)/WriteDouble(...)/WriteString(...)
Helper methods to write typed values into cells, using shared strings for text and appropriate cell types/styles. -
private static string GetColumn(int index)
Converts a zero-based column index to Excel column letters (e.g.,0 → "B",1 → "C"). Note: Starts at column B (index 0), not A. -
private int InsertSharedStringItem(string text, SharedStringTablePart)
Inserts or retrieves a shared string index. Uses_stringLookupdictionary for O(1) lookup. -
private void AddStyleSheet(SpreadsheetDocument)
Adds a date/time number format (NumberFormatId = 14) to the stylesheet and caches its index. -
internal Writer(File fileType, int encoding)
Constructor. Sets default export flags:ExportADC = false,ExportEU = true,ExportMv = false.
3. Invariants
- Cell ordering: Cells in a row must be in ascending
CellReferenceorder (enforced byInsertCellInWorksheet). - Shared string uniqueness:
_stringLookupensures each unique string is stored only once in the shared string table. - Data row indexing: Time-series data rows start at row 24 (
24 + sampleIndex). - Channel column indexing: Columns are assigned sequentially starting at column B (
GetColumn(i)wherei = 0→"B"). - Metadata row layout (fixed per channel):
- Row 6: Sample rate (Hz)
- Row 7: AA filter rate (Hz)
- Row 8: Channel index (1-based)
- Row 9: ISO code
- Row 10: Channel name (
ChannelName2) - Row 12: Serial number
- Row 13: Filter cutoff (Hz) —
0if not filtered - Row 14: Filter name — only if filtered
- Row 15: Engineering units
- Row 17: Pre-trigger samples
- Row 18: Post-trigger samples
- Row 19:
DataZeroLevelAdc - Row 20: ADC-to-EU scaling factor
- Row 21: ADC-to-mV scaling factor
- Row 23: Channel label (
"Chan {i}: {name}")
- Time calculation: Time value for sample
nis computed as:wheretime = (StartRecordSampleNumber - TriggerSampleNumber[0] + n) / SampleRateHznis adjusted forminStartTimeand per-channel start offsets.
4. Dependencies
External Dependencies
DocumentFormat.OpenXml— Core Open XML SDK for reading/writing.xlsxfiles.DTS.Common.Utilities.Logging— UsesAPILogger.Log(...)for non-fatal exceptions (e.g.,WindowAverageADCfailures).DTS.Slice.Control— ImportsFilteredData,FilteredChannelData, and related filtering types.
Internal Dependencies
DTS.Serialization— Inherits fromSerialization.File.DTS.Common.DAS.Concepts— UsesDataScalerand related types.DTS.Slice.Control— UsesSaeJ211Filter,FilteredData, andCancelRequested.Testmodel — ExpectsTest.Module.AnalogInputChannel,Test.Module.Channel, andPersistentChannelInfowithDataarray.
Dependencies on this Module
- Any code requiring XLSX export of
Testobjects (e.g., UI export buttons, batch processing pipelines) will instantiateDTS.Serialization.XLSX.Fileand callExporter.Write(...).
5. Gotchas
- Column offset:
GetColumnstarts at column B (index 0 →"B"), not A. This is hardcoded and not configurable. - String caching:
_stringLookupis reset perWritecall (cleared inWrite), but reused within a single write for efficiency. Not thread-safe. - Row caching:
RowIndexToRowis a static dictionary. It is cleared at the start of eachWrite, but if multiple threads callWriteconcurrently, race conditions may occur. - Filtered data is precomputed: When
Filtered = true, all EU data is pre-filtered into adouble[][]before streaming. This may consume significant memory for large datasets. - Template dependency: Requires
XLSXExportTemplate.xlsxin theReportTemplatessubdirectory of the application base directory. Missing file → copy failure. - GC pressure mitigation: Explicit
GC.Collect()and heap compaction are triggered after writing. This may cause latency spikes. - No export flag enforcement in data loop: The
Writemethod only exports EU data (viads.GetEU(...)), regardless ofExportADC,ExportEU, orExportMVsettings. These flags are set on theWriter, but the current implementation ignores them in the data loop. FilteredChannelDatais commented out: The propertyFilteredChannelDatais commented out inExcel.File.Writer.cs, suggesting incomplete or deprecated functionality.UseLegacyTDCSoftwareFilteringis used but not defined: In the filtering loop,UseLegacyTDCSoftwareFilteringis referenced but not declared in the visible scope — likely a field or property defined elsewhere in theWriterclass (not shown).minStartTimeis used but not validated: AssumesminStartTime≤ actual start time of data; no bounds checking is evident.filteredDatais set tonullafter use: A manual nulling offilteredDatais done, but this may be redundant with the end of scope — possibly legacy cleanup.
Documentation generated from source files Excel.File.cs and Excel.File.Writer.cs.