A real 665-byte KMZ unpacked, seven KML structures exported, and 17,289 real points round-tripped. Measured results on coordinate order, attribute loss, file sizes and a lossless exporter, with runnable Python and TypeScript.
"Export my KMZ to Excel" is one of the most common requests a GIS conversion tool receives. In the Search Console data for the project I work on, the cluster around kmz to csv, kmz a excel and excel to kmz produces steady impressions with almost no clicks — people are looking for an answer, and the pages they find are converters, not explanations.
The awkward part is that the request is underspecified. A KML file can hold points, lines, polygons with holes, nested folders, styles, HTML descriptions, custom attribute fields and image overlays. A CSV is a flat table. Something has to be discarded, and unless the exporter tells you what, you will only discover the loss three steps later when a polygon becomes a single dot.
I build geoo.app, a set of browser-local GIS converters. This article measures exactly what a KML/KMZ → CSV/Excel export keeps and loses, using real fixture files and 17,289 real point records. Every byte count, displacement and verdict below was produced by the scripts in this article.

Figure 1. A 665-byte KMZ, seven KML structures and 17,289 real points. For simple Point placemarks the export is lossless; for almost everything else it is not.
Start with the shipped fixture, testdata/kmz/simple.kmz. It is 665 bytes. It is not a new format — it is a ZIP archive containing two entries:
| Entry | Raw bytes | Compressed | Ratio |
|---|---|---|---|
image.png | 883 | 140 | 0.159 |
simple.kml | 429 | 241 | 0.562 |
| Total payload | 1,312 | 381 | — |
| On disk | — | 665 | — |
The first four bytes are 50 4b 03 04 — the ZIP local file header signature, PK\x03\x04. The remaining 284 bytes of the file are ZIP structure: local headers, the central directory, and the end-of-central-directory record. That overhead is why small KMZ files can be larger than the KML they contain, a point I return to in the companion article on KML vs KMZ and DWG vs DXF.

Figure 2. Two ZIP entries. The inner KML is byte-identical to the sibling simple.kml file.
I verified that last claim: the decompressed simple.kml inside the archive compares equal to the standalone testdata/kml/simple.kml. So unpacking a KMZ is a packaging operation, not a data conversion. Here is the fixture's KML:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Placemark>
<Style><IconStyle><Icon><href>image.png</href></Icon></IconStyle></Style>
<description><![CDATA[image.png <a href="./image.png">image.png</a>
<img src="image.png"/>]]></description>
<Point><coordinates>1,2,3</coordinates></Point>
</Placemark>
</Document>
</kml>
Even this tiny file already contains four things a CSV cannot represent: a <Style>, an HTML <description>, a relative image reference, and an altitude (3) in the coordinate tuple. A converter that reads only <coordinates> and <name> will throw all four away.
A minimal, safe reader for KMZ is short, but it needs one guard that tutorials often omit:
import zipfile, io
from pathlib import Path
from xml.etree import ElementTree as ET
KML_NS = 'http://www.opengis.net/kml/2.2'
def read_kmz(path: Path) -> bytes:
with zipfile.ZipFile(path) as z:
names = z.namelist()
# A KMZ normally has one root .kml; pick doc.kml if present.
candidates = [n for n in names if n.lower().endswith('.kml')]
if not candidates:
raise ValueError('KMZ contains no .kml document')
main = 'doc.kml' if 'doc.kml' in candidates else \
min(candidates, key=lambda n: n.count('/'))
# Path traversal guard: never extract a ZIP entry outside the target dir.
if main.startswith('/') or '..' in Path(main).parts:
raise ValueError(f'unsafe entry name: {main}')
return z.read(main)
def placemarks(kml_bytes: bytes):
root = ET.fromstring(kml_bytes)
return list(root.iter(f'{{{KML_NS}}}Placemark'))
The .. check is not paranoia. KMZ files arrive from other people, and ZIP entry names are attacker-controlled strings. If your tool extracts entries to disk rather than reading them in memory, an unguarded name is a real vulnerability.
Most "KML to CSV" implementations are some variant of this:
import csv, io
from xml.etree import ElementTree as ET
def naive_export(kml_bytes: bytes) -> bytes:
out = io.StringIO()
w = csv.writer(out, lineterminator='\n')
w.writerow(['name', 'lon', 'lat'])
for pm in ET.fromstring(kml_bytes).iter(f'{{{KML_NS}}}Placemark'):
name = pm.findtext(f'{{{KML_NS}}}name', default='')
c = pm.find(f'.//{{{KML_NS}}}coordinates')
if c is None or not c.text.strip():
continue
first = c.text.strip().split()[0].split(',')[:2]
w.writerow([name, first[0], first[1]])
return out.getvalue().encode('utf-8')
It writes one row per Placemark and takes only the first coordinate pair. That is a perfectly reasonable default for a point dataset — and a silent disaster for anything else.
I constructed seven KML structures using real city coordinates and ran this exporter against each. The table below is the measured result. "Coords" is the number of coordinate pairs in the source versus the number that survived into the CSV.
| KML structure | KML bytes | Coords | CSV rows | Lost |
|---|---|---|---|---|
Point | 214 | 1 → 1 | 1 | nothing |
Point + ExtendedData | 344 | 1 → 1 | 1 | 2 attribute fields |
Point + Style + CDATA | 353 | 1 → 1 | 1 | style, HTML description |
LineString | 256 | 3 → 1 | 1 | 2 coordinate pairs |
Polygon with hole | 458 | 8 → 1 | 1 | 7 coordinate pairs, inner ring |
MultiGeometry | 387 | 8 → 1 | 1 | 7 coordinate pairs |
Folder + GroundOverlay | 422 | 1 → 1 | 1 | folder hierarchy, 1 overlay |

Figure 3. Only a bare Point survives intact. Across the seven structures, nine distinct kinds of information are lost.
Three patterns are worth pulling out.
Geometry loss is proportional to vertex count. A LineString with three vertices becomes one row with one point. A polygon with an outer ring and an inner ring — eight coordinate pairs — also becomes one row, losing both the hole and the closure of the ring. The CSV does not say "this used to be a polygon"; the shape is simply gone, with no error.
Attributes disappear even when geometry is fine. ExtendedData is the standard KML way to attach custom fields. The naive writer never looks for it, so population and source vanish while name survives. This is the most common complaint behind "my KMZ to Excel export lost columns".
Structural and visual information has no tabular representation at all. Folders carry grouping, Style carries colours and icons, CDATA descriptions carry HTML, and GroundOverlay carries an image plus a LatLonBox — and no <coordinates> element, so the overlay produces no row whatsoever. A flat table cannot hold these. The honest answer is to say so in the UI, not to quietly omit them.
KML writes coordinates as longitude,latitude,altitude. GeoJSON writes [longitude, latitude] too. But most spreadsheets, and a lot of human-written documentation, use "lat, lon". Mixing the two up is the single most damaging error in this workflow, because the result is still a valid number.
I measured the great-circle displacement when lon,lat is read as lat,lon, using a sphere of radius 6,371,008.8 m:
| City | KML <coordinates> | Swapped legal? | Displacement |
|---|---|---|---|
| New York | -73.9857,40.7484,0 | yes | 15,082 km |
| London | -0.1276,51.5072,0 | yes | 7,493 km |
| Paris | 2.3522,48.8566,0 | yes | 6,793 km |
| Berlin | 13.4050,52.5200,0 | yes | 5,556 km |
| Tokyo | 139.6917,35.6895,0 | no | invalid latitude |
| Sydney | 151.2093,-33.8688,0 | no | invalid latitude |

Figure 5. Four valid-but-wrong swaps put cities thousands of kilometres away; two produce an illegal latitude and fail loudly.
from math import radians, sin, cos, asin, sqrt
def haversine(lon1, lat1, lon2, lat2, r=6_371_008.8):
p1, p2 = radians(lat1), radians(lat2)
dp, dl = p2 - p1, radians(lon2 - lon1)
a = sin(dp/2)**2 + cos(p1)*cos(p2)*sin(dl/2)**2
return 2*r*asin(sqrt(a))
lon, lat = -73.9857, 40.7484
print(round(haversine(lon, lat, lat, lon))) # 15081534 metres
The failure splits into two cases. If the longitude happens to be within ±90, the swapped pair is a valid coordinate and the parser accepts it — New York lands near the Indian Ocean, about 15,000 km away. If the longitude exceeds 90 (Tokyo, Sydney, most of Asia and Oceania), the swapped value is an illegal latitude and a strict parser rejects it. The loud failure is the lucky one.
Two practical rules follow. Always label the CSV columns lon and lat rather than x and y, and validate ranges on import:
function parseCoord(raw: string): { lon: number; lat: number } {
const parts = raw.split(',').map(Number);
if (parts.length < 2 || parts.some(n => !Number.isFinite(n))) {
throw new Error(`invalid KML coordinate: ${raw}`);
}
const [lon, lat] = parts; // KML is lon,lat[,alt]
if (Math.abs(lon) > 180 || Math.abs(lat) > 90) {
throw new Error(`out-of-range coordinate (did you swap lon/lat?): ${raw}`);
}
return { lon, lat };
}
To measure size rather than fidelity, I took a real point dataset shipped with the project — 17,289 named locations with WGS84 coordinates — and wrote it out four ways. The CSV has name,lon,lat; the XLSX was produced with openpyxl; the KML has one Placemark per point; the KMZ is that KML in a single-entry ZIP with deflate level 6.
| Representation | Bytes | Relative to CSV |
|---|---|---|
| CSV | 628,390 | 1.00 |
| XLSX | 493,536 | 0.79 |
| KML | 1,994,339 | 3.17 |
| KMZ (deflate 6) | 272,948 | 0.43 |

Figure 4. Both XLSX and KMZ are ZIP containers. A zipped KMZ ends up smaller than the plain CSV.
The surprising line is the last one: a KMZ containing the full KML is 43% the size of the CSV. KML is verbose, but it is repetitively verbose — <Placemark><name>... appears 17,289 times — and deflate compresses that repetition extremely well. The CSV has less redundancy to remove.
XLSX beats CSV for the same reason. I unpacked the generated workbook: the worksheet XML alone is 2,797,590 bytes uncompressed — larger than the entire KML — but compresses to 489,028 bytes. An .xlsx is a ZIP of XML parts; its on-disk size is a compression result, not a measure of how much text it contains. This matters if you are choosing an export format for a large dataset: raw XML size is not the number your users will download.
from openpyxl import Workbook
def write_xlsx(rows, path):
wb = Workbook()
ws = wb.active
ws.append(['name', 'lon', 'lat'])
for r in rows:
ws.append(list(r))
wb.save(path)
For the simple Point case, the naive exporter is fine. I verified it end to end on all 17,289 points: parse the KML, write CSV, parse the CSV, write KML back, and compare.
| Check | Result |
|---|---|
| Rows written | 17,289 |
| Names preserved | 17,289 / 17,289 |
| Coordinates exactly equal | True |
| Max positional error | 0.0 m |
| Mean positional error | 0.0 m |
| Rebuilt KML size | 1,994,320 bytes (original 1,994,339) |
def csv_to_kml(rows) -> bytes:
p = ['<?xml version="1.0" encoding="UTF-8"?>\n',
'<kml xmlns="http://www.opengis.net/kml/2.2"><Document>\n']
for name, lon, lat in rows:
p.append(f'<Placemark><name>{name}</name>'
f'<Point><coordinates>{lon},{lat},0</coordinates></Point>'
f'</Placemark>\n')
p.append('</Document></kml>\n')
return ''.join(p).encode('utf-8')
The 19-byte difference is a <name>points</name> document title in the original that the round trip does not reconstruct — a harmless reminder that "lossless" needs to be defined precisely. Coordinates and attributes were exact; document-level metadata was not.

Figure 6. One row per vertex, explicit identifiers, and a verification pass.
The fix is to change the row granularity: one row per vertex, with columns that let you rebuild the geometry.
import csv, io
from xml.etree import ElementTree as ET
def robust_export(kml_bytes: bytes) -> bytes:
out = io.StringIO()
w = csv.writer(out, lineterminator='\n')
w.writerow(['placemark_id', 'name', 'geometry_type', 'geom_index',
'ring', 'vertex_index', 'lon', 'lat', 'alt'])
root = ET.fromstring(kml_bytes)
for pid, pm in enumerate(root.iter(f'{{{KML_NS}}}Placemark')):
name = pm.findtext(f'{{{KML_NS}}}name', default='')
gid = 0
for geom in pm.iter():
tag = geom.tag.split('}')[-1]
if tag not in ('Point', 'LineString', 'LinearRing', 'Polygon'):
continue
rings = []
if tag == 'Polygon':
for boundary in ('outerBoundaryIs', 'innerBoundaryIs'):
b = geom.find(f'{{{KML_NS}}}{boundary}')
if b is not None:
for lr in b.iter(f'{{{KML_NS}}}LinearRing'):
rings.append((boundary, lr))
else:
rings.append(('', geom))
for ring_label, ring in rings:
for c in ring.iter(f'{{{KML_NS}}}coordinates'):
for vi, token in enumerate(c.text.strip().split()):
parts = token.split(',')
lon, lat = float(parts[0]), float(parts[1])
alt = parts[2] if len(parts) > 2 else ''
w.writerow([pid, name, tag, gid, ring_label, vi,
lon, lat, alt])
gid += 1
return out.getvalue().encode('utf-8')
This keeps the hole in a polygon (ring distinguishes outer from inner), preserves every vertex of a MultiGeometry, and keeps a stable placemark_id so a consumer can regroup rows. It still cannot represent styles, folders, CDATA or overlays — no flat table can. A good tool says that explicitly and offers a GeoJSON export alongside the CSV.
In a browser the same logic uses DOMParser and a Blob, with no upload:
const KML_NS = 'http://www.opengis.net/kml/2.2';
async function kmzToCsv(file: File): Promise<Blob> {
const buf = await file.arrayBuffer();
// JSZip / fflate can replace this in production.
const kml = file.name.endsWith('.kmz')
? await unzipFirstKml(new Uint8Array(buf))
: new TextDecoder().decode(buf);
const doc = new DOMParser().parseFromString(kml, 'application/xml');
if (doc.querySelector('parsererror')) throw new Error('invalid KML');
const rows: string[][] = [['name', 'lon', 'lat']];
for (const pm of Array.from(doc.getElementsByTagNameNS(KML_NS, 'Placemark'))) {
const name = pm.getElementsByTagNameNS(KML_NS, 'name')[0]?.textContent ?? '';
const coords = pm.getElementsByTagNameNS(KML_NS, 'coordinates')[0]?.textContent?.trim();
if (!coords) continue; // GroundOverlay has none
for (const token of coords.split(/\s+/)) {
const [lon, lat] = token.split(',');
rows.push([name, lon, lat]); // one row PER vertex
}
}
const csv = rows.map(r => r.map(csvEscape).join(',')).join('\n');
return new Blob([csv], { type: 'text/csv;charset=utf-8' });
}
function csvEscape(v: string): string {
return /[",\n]/.test(v) ? `"${v.replace(/"/g, '""')}"` : v;
}
Note csvEscape: place names routinely contain commas and quotes. A join-on-comma writer will silently shift columns for exactly the rows users care about most.
A CSV is not a spreadsheet yet. Three things go wrong after the file opens, and all three get reported as converter bugs:
-73.9857 is safe, but a coordinate with eight decimal places can be displayed rounded — and if the user saves the workbook, the displayed rounding can become the stored value. Format the columns as text, or set an explicit number format before any re-save.2026-11-05), identifiers with leading zeros (00123), and long numeric IDs are silently converted. Import those columns as Text, or prefix with an apostrophe. A place called 1-2 turning into 02-Jan is not a KML parsing error.utf-8-sig fixes that, but the BOM adds three bytes to the first field and trips strict parsers, so make it an option rather than the default. This is a CSV encoding decision, entirely separate from the DBF attribute encoding discussed in the Shapefile encoding article.None of these change the bytes your exporter produced. They are a useful reminder that KMZ → Excel is a two-stage pipeline — export, then import — and the second stage has its own failure modes.
openpyxl with default settings. A writer using shared strings or inline strings, or a streaming writer, will produce different byte counts.The fixtures are real files in the project's test data, and comparable public samples are on the sample data page. A ten-line check reproduces the core unpack result:
python3 - <<'PY'
import zipfile
z = zipfile.ZipFile('testdata/kmz/simple.kmz')
for i in z.infolist():
print(i.filename, i.file_size, '->', i.compress_size)
print('sibling KML matches:', z.read('simple.kml') ==
open('testdata/kml/simple.kml','rb').read())
PY
# image.png 883 -> 140
# simple.kml 429 -> 241
# sibling KML matches: True
A short FAQ:
Why does Excel show my coordinates in scientific notation? Because the cells were parsed as numbers. Write lon and lat as text, or format the columns to at least six decimal places; rounding to three decimals moves a point by tens of metres, as measured in the companion benchmark.
Can a CSV keep my polygon? Only if you write one row per vertex plus identifiers, as in section 6. A single row per placemark cannot. If you need the geometry intact, export GeoJSON instead.
Is KMZ to Excel harder than KML to Excel? Only by one unpack step. Once the inner .kml is in memory, both are the same XML parsing problem — and the inner document is byte-identical to the standalone KML in our fixture.
What about characters that are not ASCII? Use UTF-8 for the CSV and a BOM only if the target spreadsheet application specifically needs one. That is a separate problem from the encoding of DBF attributes covered in the Shapefile encoding article.
The practical summary: a KML to CSV export is lossless for points and lossy for almost everything else. Decide which one your user has, tell them what the table cannot hold, and always write lon before lat.