如何使用PHPExcel从工作表中删除所有图像

时间:2016-02-29 08:34:06

标签: phpexcel

正如标题所示,我正在使用PHPExcel来转换pdf部分中的excel文件。从表格中提取行。我想删除给定表单中的所有图像。有方法吗?

感谢。

3 个答案:

答案 0 :(得分:2)

这是工作代码:

package com.example.bipinp.mithun;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

public  class DailyEntry extends AbstractActivity implements TextWatcher {
    private Button btnsbmtentry;
    private Spinner spiner2;
    private EditText milkcaret,amount,amountp,prevbal,currentBal,totalBal;
    DatabaseHelper mydb;
    int amnt,amntp,sub;
    String sAmnt,sAmntp,sumvalue;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_daily_entry);
        mydb = new DatabaseHelper(this);


        btnsbmtentry=(Button)findViewById(R.id.btnsubmitentry);
        spiner2=(Spinner)findViewById(R.id.spinner2);
        milkcaret=(EditText)findViewById(R.id.txt1_de);
        amount=(EditText)findViewById(R.id.txt2_de);
        amountp=(EditText)findViewById(R.id.txt3_de);
        prevbal = (EditText)findViewById(R.id.txt4_de);

        totalBal = (EditText)findViewById(R.id.txt4_deTotBal);
        amount.addTextChangedListener(this);
        amountp.addTextChangedListener(this);

        adddata2();
        loadspinner();
        spiner2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                String pos = parent.getItemAtPosition(position).toString();
                String bale = mydb.balance(pos);
                prevbal.setText(bale);

            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });

    }

    private void loadspinner() {
        DatabaseHelper db = new DatabaseHelper(this);
        List<String> labels = db.getAllLabels();
        ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,R.layout.support_simple_spinner_dropdown_item,labels);
        dataAdapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item);
        spiner2.setAdapter(dataAdapter);
    }

    private void adddata2() {
        btnsbmtentry.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                boolean insertdata2 = mydb.insertdata2(spiner2.getSelectedItem().toString(),milkcaret.getText().toString(),amount.getText().toString(),amountp.getText().toString(),totalBal.getText().toString());
                if (insertdata2)
                    Toast.makeText(DailyEntry.this, "Record Inserted", Toast.LENGTH_SHORT).show();
                else
                    Toast.makeText(DailyEntry.this, "Databse Error", Toast.LENGTH_SHORT).show();
            }
        });
    }


    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {

    }

    @Override
    public void afterTextChanged(Editable s) {
        prevbal=(EditText)findViewById(R.id.txt4_de);
        currentBal = (EditText)findViewById(R.id.txt4_deCurrB);

        sAmnt = amount.getText().toString();
        sAmntp = amount.getText().toString();
        try {
            amnt = Integer.parseInt(sAmnt);
            amntp = Integer.parseInt(sAmntp);
            sub = amnt-amntp;
        }catch (NumberFormatException e){

        }
        sumvalue = String.valueOf(sub);
        currentBal.setText(sumvalue);

    }
}

感谢您的帮助。

答案 1 :(得分:2)

您可以通过使用空数组交换图像来删除图像

/** @var ArrayObject $drawingItems */
$drawingItems = $phpExcel->getActiveSheet()->getDrawingCollection();
$drawingItems->exchangeArray(array());

答案 2 :(得分:0)

显而易见的方法是使用工作表的getDrawingCollection()方法检索工作表的图像集。这将返回一个ArrayObject,您应该能够依次unset每个元素。