Link to home
Start Free TrialLog in
Avatar of puneet kumar
puneet kumar

asked on

Differentiate format

how to check .xls file is based on xml or word file because in both extension is .xls . i have a xml file having extension .xls how to check the format because if i check extension its always come like .xls .
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

The proper way is to perform a binary analysis based on 'file magic'. This would probably do it for you:
https://poi.apache.org/apidocs/dev/org/apache/poi/poifs/filesystem/FileMagic.html#valueOf-java.io.File-
Avatar of puneet kumar
puneet kumar

ASKER

Hi CEHJ can you please give me one example or some code snippet please it would be help me out more thanx in advance .i am attcahing a file here which is .xls file but format is xml i want to run a method when file is like .xls but with xml format . please let me know solution and some code snippet .
Demo.xls
I don't have one i'm afraid. You might find one in the POI distribution
please provide me some code snippet i m not getting any where ...
Are you sure that demo file is safe to upload to a public website?
Why not a quick PowerShell check?

$x = Get-Content Demo.xls -First 1

if($x.StartsWith("<?xml")) {
   write-host("This is an XML file")
}else {
   write-host("This is NOT an XML file")
}

Open in new window

This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.