带有ParamArray约束的Excel UDF,如SUMIFS

时间:2016-02-06 15:33:32

标签: excel vba excel-vba parameters paramarray

我正在尝试使用与内置package com.bloxofcode.phase1app; import android.app.AlertDialog; import android.content.Context; import android.content.res.AssetManager; import android.graphics.Bitmap; import android.graphics.Matrix; import android.graphics.Rect; import android.graphics.pdf.PdfRenderer; import android.os.ParcelFileDescriptor; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.ImageView; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class UsersManual extends AppCompatActivity { private ImageView imageView; private int currentPage = 0; private Button next, previous; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_users_manual); next = (Button) findViewById(R.id.next); previous = (Button) findViewById(R.id.previous); render(); next.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { currentPage++; render(); } }); previous.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { currentPage--; render(); } }); } private void render() { try{ imageView = (ImageView) findViewById(R.id.image); int REQ_WIDTH = imageView.getWidth(); int REQ_HEIGHT = imageView.getHeight(); Bitmap bitmap = Bitmap.createBitmap(REQ_WIDTH, REQ_HEIGHT, Bitmap.Config.ARGB_8888); //File file = new File("/sdcard/Download/sample.pdf"); AssetManager assetManager = getAssets(); InputStream in = null; OutputStream out = null; File file = new File(getFilesDir(), "Learning Python 5th Ed 2013.pdf"); try { in = assetManager.open("Learning Python 5th Ed 2013.pdf"); out = openFileOutput(file.getName(), Context.MODE_WORLD_READABLE); copyFile(in, out); in.close(); in = null; out.flush(); out.close(); out = null; } catch (Exception e) { Log.e("tag", e.getMessage()); } //ParcelFileDescriptor p = getApplicationContext().getAssets().openFd("Learning Python 5th Ed 2013.pdf").getParcelFileDescriptor(); File f = new File(getFilesDir() + "/Learning Python 5th Ed 2013.pdf"); PdfRenderer renderer = new PdfRenderer(ParcelFileDescriptor.open(f, ParcelFileDescriptor.MODE_READ_ONLY)); if(currentPage <= 0) { currentPage = 0; } else if(currentPage > renderer.getPageCount()) { currentPage = renderer.getPageCount() - 1; } Matrix m = imageView.getImageMatrix(); Rect rect = new Rect(0, 0, REQ_WIDTH, REQ_HEIGHT); renderer.openPage(currentPage).render(bitmap,rect, null, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY); imageView.setImageMatrix(m); imageView.setImageBitmap(bitmap); imageView.invalidate(); } catch(Exception e) { e.printStackTrace(); } } private void copyFile(InputStream in, OutputStream out) throws IOException { byte[] buffer = new byte[1024]; int read; while ((read = in.read(buffer)) != -1) { out.write(buffer, 0, read); } } } 类似的语法对Excel UDF进行编码,具有类似

的签名

SUMIFS

但是ParamArray必须具有偶数个元素的条件(理想情况下甚至是Typed)。这有可能吗?

例如,如果您尝试将Function myUDF(param1 As Type1, ParamArray paramRest() As Variant) As MyType输入到单元格中,Excel会抱怨使用错误数量的参数(因为ParamArray将为=SUMIFS(A:A,B:B,1,C:C),因此具有奇数个元素)。我希望Array(Range("B:B"),1,Range("C:C"))具有相同的行为。

目前我在事后处理:

myUDF

但感觉&#34;脏&#34;。

0 个答案:

没有答案