code: public void sign(Key privateKey, List<X509Certificate> x509List, String password, HashAlgorithm hashAlgorithm) throws XMLSignatureException, MarshalException, IOException, FormatNotUnderstoodException {
  		if (this.tempSignFileOS!=null) { // close it we sign only a closed temporary file
  			this.tempSignFileOS.close();
  		}
  		SignatureConfig sc = new SignatureConfig();
          sc.addSignatureFacet(new OOXMLSignatureFacet());
          sc.addSignatureFacet(new KeyInfoSignatureFacet());
          sc.addSignatureFacet(new XAdESSignatureFacet());
          sc.addSignatureFacet(new Office2010SignatureFacet());
  		sc.setKey((PrivateKey)privateKey);
  		sc.setSigningCertificateChain(x509List);
  		sc.setDigestAlgo(hashAlgorithm);
  		FileInputStream tempSignFileIS = null;
  		try {
  			
  			InputStream tmpFileInputStream = new FileInputStream(this.tempSignFile);
  			if (password==null) {
  				this.signUnencryptedOpcPackage(tmpFileInputStream, sc);
  			} else {
  				this.signEncryptedPackage(tmpFileInputStream, sc, password);
  			}
  			
  		} catch (InvalidFormatException | IOException e) {
  			LOG.error(e);
  		} finally {
  			if (this.finalOutputStream!=null) {
  				this.finalOutputStream.close();
  			}
  			if (tempSignFileIS!=null) {
  				tempSignFileIS.close();
  			}
  		}
  	}
docs: Signs the Excel OOXML file and writes it to the final outputstream
  
  @param privateKey private Key for signing
  @param x509List List of certificates for signing. First item must be the private key for signing.
  @param password optional password for encryption, if used
  @param hashAlgorithm hash algorithm to be used
  
  @throws MarshalException
  @throws XMLSignatureException
  @throws IOException
  @throws FormatNotUnderstoodException