写入xml
string row1Str0 =" <Row>";
string row1Str = " <Row>";
string row2Str = " </Row>";
string word1Str ="<Cell><Data ss:Type=\"String\"><Font html:Face=\"宋体\"x:CharSet=\"134\" x:Family=\"Swiss\" html:Color=\"#000000\"xmlns=\"http://www.w3.org/TR/REC-html40\">";
string word2Str ="</Font></Data></Cell>";
string pattern1 = "</Table>";
string breakLine = "\n";
string rowPattern="ExpandedRowCount=\"77\"";//行
NSString * patternStr = [[NSBundlemainBundle] pathForResource:@"excelPattern"ofType:@"xml"];
patternStr = [NSStringstringWithContentsOfFile:patternStr encoding:NSUTF8StringEncodingerror:nil];
const char * patternChar = [patternStrUTF8String];
vector<string>ivec1 = PersonalApiCplu::split(patternChar,pattern1);//取出所有单词套组
//绘制xml表
string insertStr;
for (int i =0; i<[[SingleTonTooldefaultMemory].wordListArraycount]; i++)
{
string rowStr;
NSArray * wordArray = [[SingleTonTooldefaultMemory].wordListArrayobjectAtIndex:i];
for (int j =0; j<[wordArray count]; j++)
{
NSString * aString = [wordArray objectAtIndex:j];
string wordStr = [aString UTF8String];
rowStr = rowStr+word1Str+wordStr+word2Str+breakLine;//<Cell><Data ss:Type=\String\> WORD </Data></Cell>
}
if (i==0)
{
insertStr = insertStr+row1Str0+breakLine+rowStr+row2Str+breakLine;
}
else
{
insertStr = insertStr+row1Str+breakLine+rowStr+row2Str+breakLine;
}
/*
<Row>
<Cell><Data ss:Type=\String\> WORD </Data></Cell>
</Row>
*/
}
string xmlStr = ivec1[0]+ insertStr + pattern1 + ivec1[1];
//把单词的数量和行数
string rowStr;
//int 转string
int i= [[SingleTonTooldefaultMemory].wordListArraycount];
string c;
ostringstream oss;
oss<<i;
c=oss.str();
string changeString ="ExpandedRowCount=\"77\"";
PersonalApiCplu::string_replace(changeString,"77",c);//行
cout<<changeString<<endl;
PersonalApiCplu::string_replace(xmlStr,rowPattern,changeString);//行
const char * aChar = xmlStr.c_str();
//写xml
NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES)
objectAtIndex:0];
NSString *filePath = [docPathstringByAppendingPathComponent:@"mylist.xml"];
string path = [filePath UTF8String];
FILE *fp =fopen(path.c_str(),"w");
fputs(aChar, fp);
fclose(fp);