在Excel文件格式的条件 [英] Conditional format on Excel file

查看:256
本文介绍了在Excel文件格式的条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是可能做到Excel的一些条件格式JXL或Apache POI或别的什么文件? API的Java例如像宏VBA?

 '濑身材的COULEUR倒差
对于i = 3翅片第1步
    范围(C&放大器;ⅰ)。选择
    Selection.FormatConditions.Delete
    Selection.FormatConditions.Add类型:= xlCellValue,运营商:= xlNotEqual,_
        一级方程式:== B与&一世
    Selection.FormatConditions(1).Interior.ColorIndex = 6


解决方案

因此​​,在目标语言,这些都是你需要的Excel对象:


  1. 在像变量创建 Excel.Application 的实例 oXlApp

  2. 使用 Excel.Application 对象,以打开目标工作簿:

    • 致电打开 oXlApp 工作簿的集合中的文件名作为参数传递给Open方法
    • 的方法

  3. 使用 oxlApp 对象的选择属性返回一个Excel 范围对象

  4. 修改选择范围如下:


    1. 执行一个删除条件格式方式在范围
    2. 财产
    3. 执行的添加条件格式命令财产的范围


      • 传递这些参数的添加方式:

        • 类型:= xlEx pression

        • 一级方程式:== $ B2<> $ C2


      • 将第一格式的这个属性条件的设置细胞色的:

        • 条件格式(1).Interior.ColorIndex = 36




  5. 调用*的保存的*在您的工作簿方法

  6. 清理调用关闭工作簿退出 oXlApp 方式和最后,释放内存!

Excel VBA中我们会做这样的事:

  activesheet.usedrange.select
Selection.FormatConditions.Delete
Selection.FormatConditions.Add类型:= xlEx pression,一级方程式:== $ B2<> $ C2
Selection.FormatConditions(1).Interior.ColorIndex = 36

这将首先选择使用的单元,然后添加一个条件格式为列B和C

另外,看到这一个
<一href=\"http://stackoverflow.com/questions/15612316/jacob-calling-vb-function-in-excel-file-without-invoking-open-statement/15618533#15618533\">StackOverFlow:雅各操作的Excel / Java的

和看 JXL指南

Is that possible to do some conditional format on Excel file with JXL or Apache POI or something else? API java Like Macro VBA for example?

' Mise en forme couleur pour différence
For i = 3 To fin Step 1
    Range("C" & i).Select
    Selection.FormatConditions.Delete
    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlNotEqual, _
        Formula1:="=B" & i
    Selection.FormatConditions(1).Interior.ColorIndex = 6 

解决方案

so, in your target language, these are the Excel Objects you need:

  1. Create an instance of Excel.Application in a variable like oXlApp
  2. use the Excel.Application object to open your target workbook:
    • Call the Open method of the oXlApp Workbooks collection passing in the filename as an argument to the Open method
  3. use the Selection property of the oxlApp object to return an Excel Range object
  4. modify the Selection or Range as below:

    1. Execute a Delete method on the FormatConditions property of the Range
    2. Execute an Add command on the FormatConditions property of the Range

      • pass in these arguments to the Add method:
        • Type:=xlExpression
        • Formula1:="=$B2<>$C2"
      • set this property of the first Format Condition to set the cells color:
        • FormatConditions(1).Interior.ColorIndex = 36

    '

  5. Call the *Save*method on your workbook
  6. Clean up calling the Close method on the Workbook then Quit on the oXlApp and finally, RELEASE MEMORY!

in Excel VBA we would do something like this:

activesheet.usedrange.select
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$B2<>$C2"
Selection.FormatConditions(1).Interior.ColorIndex = 36

this will first select the used cells, then add a conditional formatting for cols b and c

Also, see this one StackOverFlow: Manipulate Excel from Jacob/Java

and look at the JXL Guide

这篇关于在Excel文件格式的条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆