Element workBook = doc.getRootElement(); Namespace namespace = workBook.getNamespace(); Element workSheet = workBook.addElement(new QName("Worksheet",namespace)); workSheet.addAttribute("ss:Name","Sheet1"); Element names = workSheet.addElement(new QName("Names",namespace)); Element namedRange = names.addElement(new QName("NamedRange",namespace)); namedRange.addAttribute("ss:Name","Print_Area"); namedRange.addAttribute("ss:RefersTo","=Sheet1!R1C1:R45C16");
先获取root命名空间,在创建每个节点时都要指定xmlns