第一次海报,初级VBA脚本编写者。我已经在StackOverflow上查看了相关的问题,我的问题的答案就是假设的,所以我要求澄清一下。以下Excel VBA脚本旨在从90张工作簿的顶部删除所有空行。当我运行脚本时,它只影响我打开的工作表。为什么不能在所有表格中循环?
Sub Macro1()
Dim j As Long
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
For j = 10 To 1 Step -1
If Cells(j, 3) = "" Then
Rows(j).Delete
End If
Next j
Next
End Sub
答案 0 :(得分:2)
您需要告诉它在If语句和delete命令中查看所需的工作表:
Sub Macro1()
Dim j As Long
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
For j = 10 To 1 Step -1
If ws.Cells(j, 3) = "" Then
ws.Rows(j).Delete
End If
Next j
Next
End Sub
答案 1 :(得分:0)
def getRow(x : String) : Row={
val columnArray = new Array[String](4)
columnArray(0)=x.substring(0,3)
columnArray(1)=x.substring(3,13)
columnArray(2)=x.substring(13,18)
columnArray(3)=x.substring(18,22)
Row.fromSeq(columnArray)
}
Logger.getLogger("org").setLevel(Level.ERROR)
val spark = SparkSession.builder().master("local").appName("ReadingCSV").getOrCreate()
val fruits = spark.sparkContext.textFile("in/fruits.txt")
val schemaString = "id,fruitName,isAvailable,unitPrice";
val fields = schemaString.split(",").map( field => StructField(field,StringType,nullable=true))
val schema = StructType(fields)
val df = spark.createDataFrame(fruits.map { x => getRow(x)} , schema)