Convert Excel Workbook with Additional Settings

@param xml $strXML Data in XML format.
@param string $outputFile The name of output file.

@return string Returns the file path.
@throws Exception
965165
public function saveAs($strXML, $outputFile)
    {
        if ($strXML == '')
            throw new Exception('XML Data not specified');
        
        if ($outputFile == '')
            throw new Exception('Output Filename along extension not specified');
        
        $strURI = Product::$baseProductUri . '/cells/' . $this->getFileName() . '/saveAs?newfilename=' . $outputFile;
        $signedURI = Utils::Sign($strURI);
        $responseStream = Utils::processCommand($signedURI, "POST", "XML", $strXML);
        
        $v_output = Utils::validateOutput($responseStream);
        
        if ($v_output === '') {
            $strURI = Product::$baseProductUri . '/storage/file/' . $outputFile;
            $signedURI = Utils::Sign($strURI);
            $responseStream = Utils::processCommand($signedURI, "GET", "", "");

            $outputPath = AsposeApp::$outPutLocation . $outputFile;
            Utils::saveFile($responseStream, $outputPath);
            
            return $outputPath;
        } else {
            return $v_output;
        }         
    }
984986
public function getOuterXml()
	{
		if ( is_null( $this->domNode ) ) return "";
		return is_null( $this->domNode->parentNode )
			? $this->domNode->ownerDocument->saveXml( $this->domNode )
			: $this->domNode->ownerDocument->saveXml( $this->domNode->parentNode );
	}
813961
protected function loadXmlFile(string $xmlFile): SimpleXMLElement
    {
        $xmlContent = (new FileReader($xmlFile))->read();
        $xml = simplexml_load_string($xmlContent);

        if (!($xml instanceof SimpleXMLElement)) {
            $message = "Error loading XML file: $xmlFile";
            $this->log($message, Project::MSG_ERR);
            throw new BuildException($message);
        }

        return $xml;
    }
539481
void generateRaXml(Definition def, String outputDir)
   {
      if (!def.isUseAnnotation())
      {
         try
         {
            outputDir = outputDir + File.separatorChar + "src" + File.separatorChar +
                  "main" + File.separatorChar + "resources";
            FileWriter rafw = Utils.createFile("ra.xml", outputDir + File.separatorChar + "META-INF");
            RaXmlGen raGen = getRaXmlGen(def);
            raGen.generate(def, rafw);
            rafw.close();
         }
         catch (IOException ioe)
         {
            ioe.printStackTrace();
         }
      }
   }
701620
public function generateOutputPath(File $inFile, $outputPath = false)
    {
        //define path to input directory
        $inputDirectory = rtrim($inFile->isDir() ? $inFile->getRealPath() : dirname($inFile->getRealPath()), DIRECTORY_SEPARATOR);

        //trim output path
        if ($outputPath) {
            $outputPath = rtrim($outputPath, DIRECTORY_SEPARATOR);
        }

        //if a path was provided by the user, make sure it's relatively valid
        if (is_string($outputPath)) {
            //if directory output is required
            if ($this->getOutputDefinition()->getRequiredType() === 'directory') {
                //output path should not contain an extension if the output is supposed to be a directory
                $exp = explode(DIRECTORY_SEPARATOR, $outputPath);
                $name = end($exp);
                $exp = $this->safeExplodeFileName($name);
                if (count($exp) >= 2) {
                    throw new Exception\InvalidInputException(sprintf("Output for this preset is required to be a directory, the output path should not contain a file extension."));
                }

                //otherwise it must be valid, so return
                return $outputPath;
            }

            //if output can be a file, make sure the path acceptable by the output definition
            else {
                //check for a file extension provided
                $exp = explode(DIRECTORY_SEPARATOR, $outputPath);
                $name = end($exp);
                $exp = $this->safeExplodeFileName($name);

                //we assume a valid file extension
                if (count($exp) >= 2) {
                    //if contains an extension, is it valid?
                    $givenExtension = strtolower(array_pop($exp));
                    $inputExtension = strtolower($inFile->getExtension());
                    $baseName = implode(".", $exp);

                    //should it inherit the extension?  if so does it match?
                    if ($this->getOutputDefinition()->getInheritInputExtension() && ($givenExtension !== $inputExtension)) {
                        throw new Exception\InvalidInputException(sprintf("The output file extension for this preset must match the file extension of the input file."));
                    }

                    //does the output definition generally accept the given extension?
                    if (!$this->getOutputDefinition()->acceptsExtension($givenExtension)) {
                        throw new Exception\InvalidInputException(sprintf("The requested preset cannot output files with extension [%s]", $givenExtension));
                    }

                    //provided path must be valid enough, so return it
                    return $outputPath;
                }

                //otherwise we assume we've been given a directory to put the file in
                else {
                    //generate a default name, append to provided directory, try resolving a valid output extension

                    //get input filename without it's extension
                    $exp = explode(".", $inFile->getFilename());
                    if (count($exp) >= 2) {
                        array_pop($exp);
                    }
                    $baseName = implode(".", $exp);

                    //get proper output extension
                    $outputExtension = $this->resolveOutputExtension($inFile, $outputPath);

                    //default to infixing the preset key of the output file to avoid confusing
                    return $outputPath.DIRECTORY_SEPARATOR.$baseName.".".$this->getKey().".".$outputExtension;
                }
            }
        }

        //otherwise, if no path was provided
        else {
            //check output definition for required types
            if ($this->getOutputDefinition()->getRequiredType() === 'directory') {
                //default to creating directory named by preset
                return $inputDirectory.DIRECTORY_SEPARATOR.$this->getKey();
            } else {
                //otherwise default to creating new file path with format infileName.presetKey.required_or_inheritedExtension
                $outputExtension = $this->resolveOutputExtension($inFile, $outputPath);

                //get input filename without it's extension
                $exp = explode(".", $inFile->getFilename());
                if (count($exp) >= 2) {
                    array_pop($exp);
                }
                $baseName = implode(".", $exp);

                return $inputDirectory.DIRECTORY_SEPARATOR.$baseName.".".$this->getKey().".".$outputExtension;
            }
        }

        return false;
    }
14841
public function convert(DOMDocument $xmlDoc): void
    {
        foreach ($xmlDoc->getElementsByTagName('link') as $link) {
            /** @var \DOMElement $link */
            if (!$link->hasAttribute('custom:file')) {
                continue;
            }

            $content = null;
            $location = null;

            if ($link->hasAttribute('object_id')) {
                try {
                    $content = $this->loadService->loadContent($link->getAttribute('object_id'));
                    $location = $content->mainLocation;
                } catch (NotFoundException $e) {
                    $this->logger->warning(
                        'While generating links for xmltext, could not locate ' .
                        'Content object with ID ' . $link->getAttribute('object_id')
                    );
                } catch (UnauthorizedException $e) {
                    $this->logger->notice(
                        'While generating links for xmltext, unauthorized to load ' .
                        'Content object with ID ' . $link->getAttribute('object_id')
                    );
                }
            }

            if ($link->hasAttribute('node_id')) {
                try {
                    $location = $this->loadService->loadLocation($link->getAttribute('node_id'));
                    $content = $location->content;
                } catch (NotFoundException $e) {
                    $this->logger->warning(
                        'While generating links for xmltext, could not locate ' .
                        'Location with ID ' . $link->getAttribute('node_id')
                    );
                } catch (UnauthorizedException $e) {
                    $this->logger->notice(
                        'While generating links for xmltext, unauthorized to load ' .
                        'Location with ID ' . $link->getAttribute('node_id')
                    );
                }
            }

            if ($content !== null && $content->hasField('file')) {
                $field = $content->getField('file');
                if (!$field->isEmpty()) {
                    $url = $this->router->generate('ngsite_download', ['contentId' => $content->id, 'fieldId' => $field->id, 'isInline' => $link->hasAttribute('custom:inline')]);
                }
            }

            if (empty($url) && $location !== null) {
                $link->setAttribute('url', $this->router->generate($location));
            } elseif (!empty($url)) {
                $link->setAttribute('url', $url);
            } else {
                $link->setAttribute('url', '');
            }

            if ($link->hasAttribute('anchor_name')) {
                $link->setAttribute('url', $link->getAttribute('url') . '#' . $link->getAttribute('anchor_name'));
            }

            // With this we disable the original pre-converter
            // (and hopefully all other that touch link element)
            $link->removeAttribute('object_id');
            $link->removeAttribute('node_id');
            $link->removeAttribute('anchor_name');
        }
    }
1248767
public function convertLocalFile($inputPath, $outputFormat)
    {
        //check whether files are set or not
        if ($inputPath == '')
            throw new Exception('Input file not specified');

        if ($outputFormat == '')
            throw new Exception('Format not specified');

        //build URI
        $strURI = Product::$baseProductUri . '/imaging/' . $this->getFileName() . '/saveAs?format=' . $outputFormat;

        //sign URI
        $signedURI = Utils::sign($strURI);

        $responseStream = Utils::uploadFileBinary($signedURI, $inputPath, 'xml', 'POST');

        $v_output = Utils::validateOutput($responseStream);

        if ($v_output === '') {
            if ($outputFormat == 'html') {
                $saveFormat = 'zip';
            } else {
                $saveFormat = $outputFormat;
            }

            $outputFilename = Utils::getFileName($inputPath) . '.' . $saveFormat;

            Utils::saveFile($responseStream, AsposeApp::$outPutLocation . $outputFilename);
            return $outputFilename;
        } else
            return $v_output;
    }
991533
function &outputText()
    {
        if ( !$this->XMLData )
        {
            $output = '';
            return $output;
        }

        $this->Tpl = eZTemplate::factory();
        $this->Res = eZTemplateDesignResource::instance();
        if ( $this->ContentObjectAttribute )
        {
            $this->Res->setKeys( array( array( 'attribute_identifier', $this->ContentObjectAttribute->attribute( 'contentclass_attribute_identifier' ) ) ) );
        }

        $this->Document = new DOMDocument( '1.0', 'utf-8' );
        $success = $this->Document->loadXML( $this->XMLData );

        if ( !$success )
        {
            $this->Output = '';
            return $this->Output;
        }

        $this->prefetch();

        $this->XMLSchema = eZXMLSchema::instance();

        // Add missing elements to the OutputTags array
        foreach( $this->XMLSchema->availableElements() as $element )
        {
            if ( !isset( $this->OutputTags[$element] ) )
            {
                 $this->OutputTags[$element] = array();
             }
        }

        $this->NestingLevel = 0;
        $params = array();

        $output = $this->outputTag( $this->Document->documentElement, $params );
        $this->Output = $output[1];

        unset( $this->Document );

        $this->Res->removeKey( 'attribute_identifier' );
        return $this->Output;
    }
436967
public static boolean list2Xls(List<?> list, String xmlPath, OutputStream outputStream) throws Exception {
        try {
            ExcelConfig config = getEasyExcel(xmlPath);
            return list2Xls(config, list, outputStream);
        } catch (Exception e1) {
            return false;
        }
    }
330074
public static function convertXmlToJson( $sourceFile, $targetFile )
	{
		$data	= self::loadXml( $sourceFile );
		return self::saveJson( $targetFile, $data );
	}
77338
public function getRowsFromXml($xml, $parent = 'sh')
    {
        $this->error = '';
        $values = array();
        
        $xmlobj = @simplexml_load_string($xml);
        if (!$xmlobj instanceof \SimpleXMLElement) {
            /* bad xml returned*/
            $this->error = "Can't read output xml";
            return false;
        }
        
        // get all rows of data
        $params = $xmlobj->xpath("/script/$parent/row");
        
        // get data for each row found.
        foreach ($params as $simpleXMLElement) {
            // If hex, get data from script->$parent->hex
            // Then can un-hex (pack) that and do simplexml load string on it, and proceed as below afterward.
            // Examples from XMLSERVICE documentation: http://174.79.32.155/wiki/index.php/XMLSERVICE/XMLSERVICECCSID
            // if hex info was sent back
            
            //  <sh rows='on' hex='on' before='819/37' after='37/819'>
            //      <row><hex>746F74616C2031363636313034</hex></row>
            //  </sh>
                
            
            /*  <cmd exec='rexx' hex='on' before='819/37' after='37/819'>
            *       <success><![CDATA[+++ success RTVJOBA USRLIBL(?) SYSLIBL(?)]]></success>
            *       <row><data desc='USRLIBL'><hex><![CDATA[5147504C20202020202020]]></hex></data></row>
            *       <row><data desc='SYSLIBL'><hex><![CDATA[5153595320202020202020]]></hex></data></row>
            *   </cmd>
            */
            
            
            // if there's a data element, go down one level to it (->data).
            $element = (isset($simpleXMLElement->data)) ? $simpleXMLElement->data : $simpleXMLElement;
            
            // if a hex tag is present, de-hex (pack) the data inside that hex tag; otherwise, use the outer element's value directly.
            $data = (isset($element->hex)) ? pack("H*", (string)$element->hex) : (string)$element;
            
            // process data string received, then add to $values array.
            
            // rows will either be from parent 'cmd' or 'sh'.
            if ($parent == 'cmd') {
                // for RTV* commands,
                // attribute 'desc' of data tag will hold the output field name to which the data belongs.
                $outputFieldName = (string) $element->attributes()->desc;
                
                $data = trim($data, " \n"); // trim spaces and end-of-line chars of data that comes from REXX RTV* commands ('cmd')
                
                $values[$outputFieldName] = $data;
            } else {
                // 'sh'
                $values[] = $data; // no particular index 
            }
        }
        
        if (count($params)==0) {
            $this->error = "No rows";
            $params = $xmlobj->xpath("/script/$parent");
            foreach ($params as $simpleXMLElement) {
                if (strstr(((string)$simpleXMLElement),"+++ no output")) {
                    $this->error = "Command does not return output";
                }
                break;
            }
        }
        
        return $values;
    }
494451
public static function parseResponseConditionXml(SimpleXMLElement $xml){
        $returnValue = self::parseElementXml($xml);
        foreach($xml->responseIf as $responseIfXml){
            $returnValue['responseIf'] = self::parseResponseIfXml($responseIfXml);
            break;
        }
        foreach($xml->responseElseIf as $responseIfXml){
            if(!isset($returnValue['responseElseIfs'])){
                $returnValue['responseElseIfs'] = array();
            }
            $returnValue['responseElseIfs'][] = self::parseResponseIfXml($responseIfXml);
        }
        foreach($xml->responseElse as $responseIfXml){
            $returnValue['responseElse'] = self::parseResponseElseXml($responseIfXml);
            break;
        }
        return $returnValue;
    }
1123276
private function getPhonePrefixLanguagePairFromFilename($outputFile)
    {
        $parts = explode(DIRECTORY_SEPARATOR, $outputFile);

        $returnObj = new \stdClass();
        $returnObj->language = $parts[0];

        $returnObj->prefix = $this->getCountryCodeFromTextFileName($parts[1]);

        return $returnObj;
    }
1255802
function inputListXML( &$listNode, $currentSectionLevel, $listSectionLevel = null, $noParagraphs = true )
    {
        $output = '';
        $tagName = $listNode instanceof DOMNode ? $listNode->nodeName : '';

        switch ( $tagName )
        {
            case 'paragraph' :
            {
                $output .= $this->inputParagraphXML( $listNode,
                                                     $currentSectionLevel,
                                                     $listSectionLevel,
                                                     $noParagraphs );
            }break;

            case 'section' :
            {
                $listSectionLevel += 1;
                $output .= $this->inputSectionXML( $listNode, $currentSectionLevel, $listSectionLevel );
            }break;

            case '#text' :
            {
                //ignore whitespace
            }break;

            default :
            {
                eZDebug::writeError( "Unsupported tag at this level: $tagName", __METHOD__ );
            }break;
        }
        return $output;
    }
193911
public static boolean WriteXml(ExcelConfig dlExcel, String xmlPath) throws Exception {
        //写入xml
        return XmlUtil.toXml(dlExcel, new File(xmlPath));
    }
967614
public function convert(string $outputFile, string $format, array $params = array()): ExportResult
    {
        try {
            $this->getVerb()->setOutputFile($outputFile)
                ->setFormat($format)
                ->setParameters($params);

            $result = self::getCommand()->execute($this->getVerb());
            if (!$result->isSuccess()) {
                if ($result->hasException()) {
                    throw $result->getException();
                }
                throw new \RuntimeException('Unknown error: ', $result->getExitCode());
            }
            return $result;
        } catch (\Exception $e) {
            throw new ConverterException('Conversion failed', ErrorCodes::EXECUTION_FAILURE, $e);
        }
    }
649395
public function parseFromXml($strXml)
    {
        $this->rules = array();
        $xml = simplexml_load_string($strXml);
        if (!isset($xml->Rule)) return;
        $this->rules = array();
        foreach ($xml->Rule as $rule) {
            $id = strval($rule->ID);
            $prefix = strval($rule->Prefix);
            $status = strval($rule->Status);
            $actions = array();
            foreach ($rule as $key => $value) {
                if ($key === 'ID' || $key === 'Prefix' || $key === 'Status') continue;
                $action = $key;
                $timeSpec = null;
                $timeValue = null;
                foreach ($value as $timeSpecKey => $timeValueValue) {
                    $timeSpec = $timeSpecKey;
                    $timeValue = strval($timeValueValue);
                }
                $actions[] = new LifecycleAction($action, $timeSpec, $timeValue);
            }
            $this->rules[] = new LifecycleRule($id, $prefix, $status, $actions);
        }
        return;
    }