Thursday, 15 May 2014

Error while generating .xls file and opening in an UIWebview iOS -



Error while generating .xls file and opening in an UIWebview iOS -

i've generated .xls file using piece of code , saved within documents directry.

nsmutablestring *excel = [[nsmutablestring alloc] init]; //excel sheet header [excel appendstring:@"<?xml version=\"1.0\"?>\n<?mso-application progid=\"excel.sheet\"?>\n<workbook xmlns=\"urn:schemas-microsoft-com:office:spreadsheet\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" "]; [excel appendstring:@"xmlns:x=\"urn:schemas-microsoft-com:office:excel\" xmlns:ss=\"urn:schemas-microsoft-com:office:spreadsheet\" xmlns:html=\"http://www.w3.org/tr/rec-html40\">\n<documentproperties xmlns=\"urn:schemas-microsoft-com:office:office\">"]; [excel appendstring:@"<lastauthor>kuzora</lastauthor>"]; [excel appendstring:[nsstring stringwithformat:@"<created>%@</created>",[nsdate date]]]; [excel appendstring:@"<version>11.5606</version>\n</documentproperties>\n<excelworkbook xmlns=\"urn:schemas-microsoft-com:office:excel\">\n<windowheight>6690</windowheight>\n<windowwidth>14355</windowwidth>"]; [excel appendstring:@"<windowtopx>360</windowtopx>\n<windowtopy>75</windowtopy>\n<protectstructure>false</protectstructure>\n<protectwindows>false</protectwindows>\n</excelworkbook>\n<styles>"]; [excel appendstring:@"<style ss:id=\"default\" ss:name=\"normal\">\n<alignment ss:vertical=\"bottom\"/>\n<borders/>\n<font/>\n<interior/>\n<numberformat/>\n<protection/>\n</style>"]; [excel appendstring:@"<style ss:id=\"s21\">\n<numberformat ss:format=\"medium date\"/>\n</style><style ss:id=\"s22\">\n<numberformat ss:format=\"short date\"/>\n</style></styles>"]; //excel sheet content [excel appendstring:@"<worksheet ss:name=\"user\">"]; [excel appendstring:@"<table ss:expandedcolumncount=\"4\" ss:expandedrowcount=\"1\" x:fullcolumns=\"1\" x:fullrows=\"1\">"]; [excel appendstring:@"<row>"]; [excel appendstring:@"<cell><data ss:type=\"string\">traineedetailid</data></cell>"]; [excel appendstring:@"<cell><data ss:type=\"string\">name</data></cell>"]; [excel appendstring:@"<cell><data ss:type=\"string\">dob</data></cell>"]; [excel appendstring:@"<cell><data ss:type=\"string\">heightfeet</data></cell>"]; [excel appendstring:@"</row>"]; [excel appendstring:@"</table>"]; [excel appendstring:@"</worksheet>"]; [excel appendstring:@"</workbook>"]; filepath = [[self applicationdocumentsdirectory] stringbyappendingpathcomponent:@"somename.xls"]; info = [excel datausingencoding:nsutf8stringencoding allowlossyconversion:false]; if(![data writetofile:filepath atomically:yes]) return;

the .xls file

when tried open in uiwebview giving me error "an error occurred while reading document.". .xls file has been created successfully. need know why webview cant able open file. tried opening other .xls file in webview success. why cant open .xls file i've created? suggestions.

you can seek code load generated excel:

nsstring *resourcedbfolderpath; nsfilemanager *filemanager = [nsfilemanager defaultmanager]; nserror *error1; nsarray *paths = nssearchpathfordirectoriesindomains( nsdocumentdirectory, nsuserdomainmask, yes); nsstring *documentsdirectory = [paths objectatindex:0]; nsstring *documentdbfolderpath = [documentsdirectory stringbyappendingpathcomponent:[nsstring stringwithformat:@"somename.xls"]]; bool success = [filemanager fileexistsatpath:documentdbfolderpath]; nsurl *url = [nsurl fileurlwithpath: documentdbfolderpath]; nsurlrequest *request = [nsurlrequest requestwithurl:url]; if(success) [webview loadrequest:request];

please allow me know whether code helps you.

ios

No comments:

Post a Comment