我正在尝试从 50 个 excel 文件中删除一行,为此我正在 flex 中制作一个工具来遍历文件夹,找到 xls 文件,然后对其执行操作。我在这里面临两个问题: 1. 我有一个循环它对文件夹进行迭代,一旦找到 xls,它应该调用一个函数来删除该行并返回 for 循环并继续处理文件夹中的其他 excel 文件。但它没有这样做。
2.我无法在 excel 中删除和行。我正在使用 as3xls 来处理 excel。在此我将不需要的行的值设置为空白,因为我不知道如何删除它。
我是flex新手,所以请帮忙。
enter code here
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:mx="library://ns.adobe.com/flex/mx" layout="absolute"
creationComplete="onCreate(event)">
<fx:Script>
<![CDATA[
import com.as3xls.xls.Cell;
import com.as3xls.xls.ExcelFile;
import com.as3xls.xls.Sheet;
import flash.filesystem.FileMode;
import flash.utils.Timer;
// import flash.events.TimerEvents;
import mx.collections.ArrayCollection;
import mx.controls.Alert;
private var sheet:Sheet;
private var interval: uint;
private var loadedFile:ByteArray;
function trigger():void { setTimeout(doIt, 10000); }
function doIt():void { }
private function onCreate(e:Event):void
{
var fileDirectry:File = File.documentsDirectory.resolvePath("D:/temp");
var excelFile:File = null;
var files:Array = fileDirectry.getDirectoryListing();
for(var i:int = 0; i < files.length; i++){
var temp:File = files[i];
if(temp.extension == "xls"){
excelFile = temp;
break;
//var request:URLRequest = new URLRequest(excelFile.nativePath);
//var urlLoader:URLLoader = new URLLoader(request);
//urlLoader.addEventListener(Event.COMPLETE, onURLLoaderComplete); // Once file loaded, function call onURLLoaderComplete
//urlLoader.dataFormat = URLLoaderDataFormat.BINARY; // to Read Data in Binary Format
//urlLoader.load(request);
//trigger();
// interval=setTimout( onCreate(event) ,200);
}
}
var request:URLRequest = new URLRequest(excelFile.nativePath);
var urlLoader:URLLoader = new URLLoader(request);
urlLoader.addEventListener(Event.COMPLETE, onURLLoaderComplete); // Once file loaded, function call onURLLoaderComplete
urlLoader.dataFormat = URLLoaderDataFormat.BINARY; // to Read Data in Binary Format
urlLoader.load(request);
}
private function onURLLoaderComplete(event:Event):void
{
loadedFile = event.target.data;
var excelFile:ExcelFile = new ExcelFile();
excelFile.loadFromByteArray(loadedFile);
sheet = excelFile.sheets[0]; // Reads sheet1
//trace(sheet.getCell(1,1).value);
//Alert.show(sheet.getCell(0,0).value)// getCell(Row, Col)
var rows:int = sheet.rows;
var cols:int = sheet.cols;
for(var i:int = 0; i < rows; i++){
for(var j:int = 0; j < cols; j++){
if(sheet.getCell(i,j).toString() == "second" || sheet.getCell(i,j).toString() == "Second" )
{
Alert.show(sheet.getCell(i,j-1).value)
for (var k:int =0;k< cols;k++){
sheet.setCell(i,k,'');
}
excelFile.sheets.addItem(sheet);
var ba:ByteArray = excelFile.saveToByteArray();
var fr:FileReference = new FileReference();
fr.save(ba,"SampleExport1.xls");
//sheet.
//TypeLib name and TypeDef Id
}
}
}
//Alert.show(sheet.getCell(0,0).value)
//return ;
//DG.dataProvider=sheet.values; // Imports all excel cells to Datagrid
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
</mx:WindowedApplication>