Convert Excel — To Xrdml High Quality

Standard deviations, background counts, or multi-channel detector data. The XRDML Structure (Hierarchical XML)

Dedicate rows 1 through 10 to file and instrument metadata. Your script will parse these cells to fill the XML header tags. : Sample ID (e.g., TiO2_Anatase_001 ) Cell A2 : Wavelength ( ) (e.g., 1.5406 for Cu-K Cell A3 : Scan Axis (e.g., Gonio ) Cell A4 : Start Angle (e.g., 10.00 ) Cell A5 : End Angle (e.g., 80.00 ) Clean the Data Columns Start your numerical data on a fixed row (e.g., Row 12). Column A (

This article provides a comprehensive guide on how to achieve accurate, high-quality conversions, ensuring your data maintains its integrity, including 2θ angles, intensities, and metadata. Understanding the Goal: Why Convert Excel to XRDML?

: The actual core container holding the numerical arrays. convert excel to xrdml high quality

steps). Small rounding errors in Excel can cause phase analysis software to reject the file.

import pandas as pd import xml.etree.ElementTree as ET from xml.dom import minidom def convert_excel_to_xrdml(excel_path, output_path): # 1. Read metadata and data from Excel meta_df = pd.read_excel(excel_path, nrows=5, header=None) data_df = pd.read_excel(excel_path, skiprows=10) # Assumes data starts at row 11 sample_id = str(meta_df.iloc[0, 1]) wavelength = str(meta_df.iloc[1, 1]) start_2theta = float(meta_df.iloc[2, 1]) end_2theta = float(meta_df.iloc[3, 1]) # Extract data columns twotheta = data_df.iloc[:, 0].tolist() intensities = data_df.iloc[:, 1].astype(int).astype(str).tolist() # 2. Build the XRDML XML Structure root = ET.Element("xrdMeasurement", "xmlns": "http://panalytical.com", "status": "Completed" ) # Sample Information sample = ET.SubElement(root, "sample") id_tag = ET.SubElement(sample, "id") id_tag.text = sample_id # Scan Setup scan = ET.SubElement(root, "scan", "scanAxis": "Gonio", "mode": "Continuous") # Explicitly define 2-Theta positions positions = ET.SubElement(scan, "positions", "axis": "2Theta", "unit": "deg") start_pos = ET.SubElement(positions, "startPosition") start_pos.text = f"start_2theta:.4f" end_pos = ET.SubElement(positions, "endPosition") end_pos.text = f"end_2theta:.4f" # Append Intensity Array data_points = ET.SubElement(scan, "dataPoints") intensities_tag = ET.SubElement(data_points, "intensities", "unit": "counts") intensities_tag.text = " ".join(intensities) # 3. Pretty-print and save with UTF-8 encoding xml_str = ET.tostring(root, encoding="utf-8") parsed_xml = minidom.parseString(xml_str) pretty_xml = parsed_xml.toprettyxml(indent=" ") with open(output_path, "w", encoding="utf-8") as f: f.write(pretty_xml) print(f"Success: High-quality XRDML file generated at output_path") # Example execution # convert_excel_to_xrdml("powder_pattern.xlsx", "output_pattern.xrdml") Use code with caution. 4. Method 2: Native Excel-to-XML Mapping (No-Code Approach)

with open(output_path, 'w', encoding='utf-8') as f: f.write(pretty_xml) : Sample ID (e

A "high-quality" conversion means more than just dumping two columns (2-Theta and Intensity) into a text file. A valid XRDML file relies on a specific XML schema. The file is fundamentally divided into two main blocks: 1. The Header (Metadata)

Using a Python script ensures the highest quality conversion. It builds a valid XML structure matching the official Malvern Panalytical schema. 1. Prepare the Excel File

pip install pandas

The export process rebuilds the XML schema correctly, preserving step time and geometry—critical for quantitative phase analysis.

Excel files typically store diffraction data as simple two-column or three-column text. : 2-Theta ( ) scattering angles. Y-axis : Intensity counts or counts per second (CPS).

Open your Excel file within the software and save it as an .XRDML file to ensure all diffraction-specific tags are correctly mapped. 2. Using Specialized Conversion Tools : The actual core container holding the numerical arrays