Hoang  Ha

Hoang Ha

1677216133

Cách bỏ ẩn hàng và cột trong Excel

Tìm hiểu cách bỏ ẩn hàng và cột trong Excel. Bỏ ẩn hoàn toàn các hàng và cột bằng Excel VBE (Visual Basic Editor). Hướng dẫn này có thể áp dụng cho Excel 2007 đến 2016, nhưng nó cũng có thể hướng dẫn bạn cách thực hiện trong các phiên bản Excel khác.

Nếu bạn đang làm việc với một bảng tính chứa dữ liệu nhạy cảm hoặc riêng tư thì một số hàng và cột có thể bị ẩn. Bạn cũng có thể cần ẩn thông tin hoặc dữ liệu không quan trọng mà bạn không muốn người khác nhìn thấy trong bảng tính của mình.

Trong những trường hợp này, bạn có thể cần phải bỏ ẩn các hàng và cột bị ẩn đó trước khi bắt đầu cập nhật bảng tính để kiểm tra dữ liệu chứa trong đó.

Trong bài viết này, bạn sẽ học cách bỏ ẩn hàng và cột trong Excel. Bạn cũng sẽ tìm hiểu cách hiện tất cả các hàng và cột trong trường hợp tất cả chúng đều bị ẩn.

Hướng dẫn này có thể áp dụng cho Excel 2007 đến 2016, nhưng nó cũng có thể hướng dẫn bạn cách thực hiện trong các phiên bản Excel khác.

Những gì chúng tôi sẽ bao gồm

  • Cách tìm hàng và cột ẩn
  • Cách bỏ ẩn một cột trong Excel
  • Cách bỏ ẩn một hàng trong Excel
  • Cách bỏ ẩn tất cả các hàng và cột ẩn trong tab trang chủ
  • Cách bỏ ẩn tất cả các hàng và cột cùng một lúc với VBA Micro
  • Phần kết luận

Trước khi đi sâu vào cách hiện các hàng và cột trong Excel, chúng ta hãy xem cách tìm các hàng và cột bị ẩn.


Cách tìm hàng và cột ẩn

Bạn có thể phát hiện một hàng hoặc cột bị ẩn bằng cách nhìn vào các đường ngăn cách từng hàng và từng cột. Nếu các đường gấp đôi hoặc có màu xanh lục, điều đó có nghĩa là có một hàng hoặc cột bị ẩn.

Ảnh chụp màn hình-2023-02-23-at-11.49.19

Ngoài ra, hãy xem bảng tính, nếu các cột bị thiếu chữ cái hoặc thiếu số trong các hàng thì có thể có các hàng và cột bị ẩn trong bảng tính.

Ảnh chụp màn hình-2023-02-23-at-11.49.43

Cách bỏ ẩn một cột trong Excel

Bạn có thể bỏ ẩn một cột nào đó bằng cách nhấp chuột phải vào dòng kép cho biết cột bị ẩn và chọn “bỏ ẩn”:

Ảnh chụp màn hình-2023-02-23-at-11.56.27

Ảnh chụp màn hình-2023-02-23-at-13.04.02

Cách bỏ ẩn một hàng trong Excel

Nếu bạn muốn bỏ ẩn một hàng, hãy nhấp chuột phải vào dòng kép được chỉ định bằng màu xanh lá cây (hoặc nếu có thể, một màu khác dựa trên cài đặt của người dùng), sau đó chọn “bỏ ẩn”:

Ảnh chụp màn hình-2023-02-23-at-12.01.11

Ảnh chụp màn hình-2023-02-23-at-13.08.06

Cách bỏ ẩn tất cả các hàng và cột ẩn trong tab trang chủ

Để hiện tất cả các hàng, hãy chọn tất cả các hàng và cột bằng cách nhấn CTRL + A, chuyển đến tab Home, định vị các ô và nhấp vào mũi tên trên "Định dạng":

Ảnh chụp màn hình-2023-02-23-at-12.07.16

Trong chế độ hiển thị, di chuột vào “Hide and Unhide”, sau đó chọn “Unhide Rows”:

Ảnh chụp màn hình-2023-02-23-at-12.08.14

Để bỏ ẩn tất cả các cột bị ẩn, bạn phải làm theo quy trình tương tự, nhưng lần này, bạn phải chọn “Bỏ ẩn các cột”.

Cách bỏ ẩn tất cả các hàng và cột cùng một lúc với VBA Micro

Nếu bạn đang xử lý một bảng tính lớn, các quy trình mà chúng ta vừa thảo luận có thể khiến bạn thấy nhàm chán.

Thay vì bỏ ẩn từng hàng và cột hoặc bỏ ẩn hàng và cột, bạn có thể chạy một số mã VBA (Visual Basic for Applications) để làm điều đó.

Đây là cách chạy mã VBA trong Excel:

Nhấn ALT + F11 (hoặc Option + F11 trên máy Mac) để mở VBE (Visual Basic Editor):

Ảnh chụp màn hình-2023-02-23-at-12.31.01

Nhấp chuột phải vào sổ làm việc hiện tại của bạn, di chuột vào “Chèn” và chọn “Mô-đun”:

Ảnh chụp màn hình-2023-02-23-at-12.32.53

Dán mã này vào trình chỉnh sửa:

Sub UnhideAllRowsAndColumns()
  Cells.EntireColumn.Hidden = False
  Cells.EntireRow.Hidden = False
End Sub

Đóng hộp thoại và quay lại trang tính của bạn.

Tiếp theo, bạn cần chạy VBA Micro. Nhấn ALT + F8 và bạn sẽ thấy một cái gì đó như thế này:

Ảnh chụp màn hình-2023-02-23-at-12.38.39

Mở rộng nó và nhấp vào “Chạy”:

Ảnh chụp màn hình-2023-02-23-at-12.40.04

Giờ đây, mọi hàng và cột sẽ hiển thị:

Ảnh chụp màn hình-2023-02-23-at-13.03.28

Phần kết luận

Bài viết này hướng dẫn bạn cách hiện một hàng hoặc một cột trong Excel.

Các ví dụ chúng tôi đã xem cho bạn thấy cách hiện các hàng và cột riêng lẻ, hiện tất cả các cột và hiện tất cả các hàng.

Chúng tôi cũng đã xem xét cách bạn có thể bỏ ẩn hoàn toàn các hàng và cột bằng Excel VBE (Trình soạn thảo Visual Basic).

Nếu bạn thấy bài viết này hữu ích, hãy chia sẻ nó với bạn bè và gia đình của bạn.

Nguồn: https://www.freecodecamp.org

#excel

What is GEEK

Buddha Community

Cách bỏ ẩn hàng và cột trong Excel
Gerhard  Brink

Gerhard Brink

1622622360

Data Validation in Excel

Data Validation in Excel

In this tutorial, let’s discuss what data validation is and how it can be implemented in MS-Excel. Let’s start!!!

What Is Data Validation in Excel?

Data Validation is one of the features in MS-Excel which helps in maintaining the consistency of the data in the spreadsheet. It controls the type of data that can enter in the data validated cells.

Data Validation in MS Excel

Now, let’s have a look at how data validation works and how to implement it in the worksheet:

To apply data validation for the cells, then follow the steps.

1: Choose to which all cells the validation of data should work.

2: Click on the DATA tab.

3: Go to the Data Validation option.

4: Choose the drop down option in it and click on the Data Validation.

data validation in Excel

Once you click on the data validation menu from the ribbon, a box appears with the list of data validation criteria, Input message and error message.

Let’s first understand, what is an input message and error message?

Once, the user clicks the cell, the input message appears in a small box near the cell.

If the user violates the condition of that particular cell, then the error message pops up in a box in the spreadsheet.

The advantage of both the messages is that the input and as well as the error message guide the user about how to fill the cells. Both the messages are customizable also.

Let us have a look at how to set it up and how it works with a sample

#ms excel tutorials #circle invalid data in excel #clear validation circles in excel #custom data validation in excel #data validation in excel #limitation in data validation in excel #setting up error message in excel #setting up input message in excel #troubleshooting formulas in excel #validate data in excel

Hoang  Ha

Hoang Ha

1677216133

Cách bỏ ẩn hàng và cột trong Excel

Tìm hiểu cách bỏ ẩn hàng và cột trong Excel. Bỏ ẩn hoàn toàn các hàng và cột bằng Excel VBE (Visual Basic Editor). Hướng dẫn này có thể áp dụng cho Excel 2007 đến 2016, nhưng nó cũng có thể hướng dẫn bạn cách thực hiện trong các phiên bản Excel khác.

Nếu bạn đang làm việc với một bảng tính chứa dữ liệu nhạy cảm hoặc riêng tư thì một số hàng và cột có thể bị ẩn. Bạn cũng có thể cần ẩn thông tin hoặc dữ liệu không quan trọng mà bạn không muốn người khác nhìn thấy trong bảng tính của mình.

Trong những trường hợp này, bạn có thể cần phải bỏ ẩn các hàng và cột bị ẩn đó trước khi bắt đầu cập nhật bảng tính để kiểm tra dữ liệu chứa trong đó.

Trong bài viết này, bạn sẽ học cách bỏ ẩn hàng và cột trong Excel. Bạn cũng sẽ tìm hiểu cách hiện tất cả các hàng và cột trong trường hợp tất cả chúng đều bị ẩn.

Hướng dẫn này có thể áp dụng cho Excel 2007 đến 2016, nhưng nó cũng có thể hướng dẫn bạn cách thực hiện trong các phiên bản Excel khác.

Những gì chúng tôi sẽ bao gồm

  • Cách tìm hàng và cột ẩn
  • Cách bỏ ẩn một cột trong Excel
  • Cách bỏ ẩn một hàng trong Excel
  • Cách bỏ ẩn tất cả các hàng và cột ẩn trong tab trang chủ
  • Cách bỏ ẩn tất cả các hàng và cột cùng một lúc với VBA Micro
  • Phần kết luận

Trước khi đi sâu vào cách hiện các hàng và cột trong Excel, chúng ta hãy xem cách tìm các hàng và cột bị ẩn.


Cách tìm hàng và cột ẩn

Bạn có thể phát hiện một hàng hoặc cột bị ẩn bằng cách nhìn vào các đường ngăn cách từng hàng và từng cột. Nếu các đường gấp đôi hoặc có màu xanh lục, điều đó có nghĩa là có một hàng hoặc cột bị ẩn.

Ảnh chụp màn hình-2023-02-23-at-11.49.19

Ngoài ra, hãy xem bảng tính, nếu các cột bị thiếu chữ cái hoặc thiếu số trong các hàng thì có thể có các hàng và cột bị ẩn trong bảng tính.

Ảnh chụp màn hình-2023-02-23-at-11.49.43

Cách bỏ ẩn một cột trong Excel

Bạn có thể bỏ ẩn một cột nào đó bằng cách nhấp chuột phải vào dòng kép cho biết cột bị ẩn và chọn “bỏ ẩn”:

Ảnh chụp màn hình-2023-02-23-at-11.56.27

Ảnh chụp màn hình-2023-02-23-at-13.04.02

Cách bỏ ẩn một hàng trong Excel

Nếu bạn muốn bỏ ẩn một hàng, hãy nhấp chuột phải vào dòng kép được chỉ định bằng màu xanh lá cây (hoặc nếu có thể, một màu khác dựa trên cài đặt của người dùng), sau đó chọn “bỏ ẩn”:

Ảnh chụp màn hình-2023-02-23-at-12.01.11

Ảnh chụp màn hình-2023-02-23-at-13.08.06

Cách bỏ ẩn tất cả các hàng và cột ẩn trong tab trang chủ

Để hiện tất cả các hàng, hãy chọn tất cả các hàng và cột bằng cách nhấn CTRL + A, chuyển đến tab Home, định vị các ô và nhấp vào mũi tên trên "Định dạng":

Ảnh chụp màn hình-2023-02-23-at-12.07.16

Trong chế độ hiển thị, di chuột vào “Hide and Unhide”, sau đó chọn “Unhide Rows”:

Ảnh chụp màn hình-2023-02-23-at-12.08.14

Để bỏ ẩn tất cả các cột bị ẩn, bạn phải làm theo quy trình tương tự, nhưng lần này, bạn phải chọn “Bỏ ẩn các cột”.

Cách bỏ ẩn tất cả các hàng và cột cùng một lúc với VBA Micro

Nếu bạn đang xử lý một bảng tính lớn, các quy trình mà chúng ta vừa thảo luận có thể khiến bạn thấy nhàm chán.

Thay vì bỏ ẩn từng hàng và cột hoặc bỏ ẩn hàng và cột, bạn có thể chạy một số mã VBA (Visual Basic for Applications) để làm điều đó.

Đây là cách chạy mã VBA trong Excel:

Nhấn ALT + F11 (hoặc Option + F11 trên máy Mac) để mở VBE (Visual Basic Editor):

Ảnh chụp màn hình-2023-02-23-at-12.31.01

Nhấp chuột phải vào sổ làm việc hiện tại của bạn, di chuột vào “Chèn” và chọn “Mô-đun”:

Ảnh chụp màn hình-2023-02-23-at-12.32.53

Dán mã này vào trình chỉnh sửa:

Sub UnhideAllRowsAndColumns()
  Cells.EntireColumn.Hidden = False
  Cells.EntireRow.Hidden = False
End Sub

Đóng hộp thoại và quay lại trang tính của bạn.

Tiếp theo, bạn cần chạy VBA Micro. Nhấn ALT + F8 và bạn sẽ thấy một cái gì đó như thế này:

Ảnh chụp màn hình-2023-02-23-at-12.38.39

Mở rộng nó và nhấp vào “Chạy”:

Ảnh chụp màn hình-2023-02-23-at-12.40.04

Giờ đây, mọi hàng và cột sẽ hiển thị:

Ảnh chụp màn hình-2023-02-23-at-13.03.28

Phần kết luận

Bài viết này hướng dẫn bạn cách hiện một hàng hoặc một cột trong Excel.

Các ví dụ chúng tôi đã xem cho bạn thấy cách hiện các hàng và cột riêng lẻ, hiện tất cả các cột và hiện tất cả các hàng.

Chúng tôi cũng đã xem xét cách bạn có thể bỏ ẩn hoàn toàn các hàng và cột bằng Excel VBE (Trình soạn thảo Visual Basic).

Nếu bạn thấy bài viết này hữu ích, hãy chia sẻ nó với bạn bè và gia đình của bạn.

Nguồn: https://www.freecodecamp.org

#excel

Ananya Gupta

Ananya Gupta

1604922206

Top 7 Advantages Of Advanced Excel Learning

Advanced Excel Certification offers numerous job opportunities that have come up. Lately, companies search for a talented personality who holds great knowledge in excel. However, simply basic knowledge isn’t sufficient. If you would like to be a part of a well-renowned company then you want to have the excel certification matching industrial standards.

Whether you’re seeking higher growth within an equivalent company or expecting an honest hike from the new company, complicated excel training courses with certification can surely increase your chances to be on the brink of the success ladder. Join an advanced online excel training class and improve your skills.

Know More About Advanced Excel?

The word itself explains the meaning of this course. this is often one quite skill that sets a learning benchmark for MS Excel. It offers a transparent insight to all or any of the simplest and therefore the most advanced features that are now available within the current version of Microsoft Excel.

In this competitive era where your colleagues would equally be striving to urge a far better post than you, if you excel yourself in some good certification courses then surely there’s no looking back for you.

This type of certification is all about brushing up your administration, management, and analytical skills which in today’s market is sort of important. To match up with the flexible needs of the clients, it’s important for you to be advanced and for this such training can certainly be helpful.

Some Mind-Blowing Benefits You Get:

There are ample Excel Training Courses that you simply may encounter, but choosing a certification course in Advanced excel possesses its perks for you also as for the corporate. Listed are a few that you simply got to know.

1.There is a superior recognition that you simply get
2.As compared to non-certified professionals, you occupy the highest at the competition
3.Employers will have you ever within the priority for giant important projects
4.If you’re a freelancer, then such advanced training is often an excellent learning experience
5.For those that wish to urge within the management, the world can have a boosting knowledge
6.Administration skills also get brushed up and a replacement range of job opportunities opens
7.There is an honest hike in PayScale soon after you show your skills and certification to your HR

Quick Tip which will Help:

If you’re getting to join a web course to urge such certification then see thereto that the trainer who is going to be taking care of you during this course is very experienced and may provide you with the simplest possible assistance.

Now you’ll boost your knowledge during a spreadsheet, play with new financial

#advanced excel online training #advanced excel online course #advanced excel training #advanced excel course #advanced excel training in noida #advanced excel training in delhi

Josefa  Corwin

Josefa Corwin

1659852060

A Template Language That Completely Separates Structure and Logic/Ruby

Curly

Curly is a template language that completely separates structure and logic. Instead of interspersing your HTML with snippets of Ruby, all logic is moved to a presenter class.

Installing

Installing Curly is as simple as running gem install curly-templates. If you're using Bundler to manage your dependencies, add this to your Gemfile

gem 'curly-templates'

Curly can also install an application layout file, replacing the .erb file commonly created by Rails. If you wish to use this, run the curly:install generator.

$ rails generate curly:install

How to use Curly

In order to use Curly for a view or partial, use the suffix .curly instead of .erb, e.g. app/views/posts/_comment.html.curly. Curly will look for a corresponding presenter class named Posts::CommentPresenter. By convention, these are placed in app/presenters/, so in this case the presenter would reside in app/presenters/posts/comment_presenter.rb. Note that presenters for partials are not prepended with an underscore.

Add some HTML to the partial template along with some Curly components:

<!-- app/views/posts/_comment.html.curly -->
<div class="comment">
  <p>
    {{author_link}} posted {{time_ago}} ago.
  </p>

  {{body}}

  {{#author?}}
    <p>{{deletion_link}}</p>
  {{/author?}}
</div>

The presenter will be responsible for providing the data for the components. Add the necessary Ruby code to the presenter:

# app/presenters/posts/comment_presenter.rb
class Posts::CommentPresenter < Curly::Presenter
  presents :comment

  def body
    SafeMarkdown.render(@comment.body)
  end

  def author_link
    link_to @comment.author.name, @comment.author, rel: "author"
  end

  def deletion_link
    link_to "Delete", @comment, method: :delete
  end

  def time_ago
    time_ago_in_words(@comment.created_at)
  end

  def author?
    @comment.author == current_user
  end
end

The partial can now be rendered like any other, e.g. by calling

render 'comment', comment: comment
render comment
render collection: post.comments

Curly components are surrounded by curly brackets, e.g. {{hello}}. They always map to a public method on the presenter class, in this case #hello. Methods ending in a question mark can be used for conditional blocks, e.g. {{#admin?}} ... {{/admin?}}.

Identifiers

Curly components can specify an identifier using the so-called dot notation: {{x.y.z}}. This can be very useful if the data you're accessing is hierarchical in nature. One common example is I18n:

<h1>{{i18n.homepage.header}}</h1>
# In the presenter, the identifier is passed as an argument to the method. The
# argument will always be a String.
def i18n(key)
  translate(key)
end

The identifier is separated from the component name with a dot. If the presenter method has a default value for the argument, the identifier is optional – otherwise it's mandatory.

Attributes

In addition to an identifier, Curly components can be annotated with attributes. These are key-value pairs that affect how a component is rendered.

The syntax is reminiscent of HTML:

<div>{{sidebar rows=3 width=200px title="I'm the sidebar!"}}</div>

The presenter method that implements the component must have a matching keyword argument:

def sidebar(rows: "1", width: "100px", title:); end

All argument values will be strings. A compilation error will be raised if

  • an attribute is used in a component without a matching keyword argument being present in the method definition; or
  • a required keyword argument in the method definition is not set as an attribute in the component.

You can define default values using Ruby's own syntax. Additionally, if the presenter method accepts arbitrary keyword arguments using the **doublesplat syntax then all attributes will be valid for the component, e.g.

def greetings(**names)
  names.map {|name, greeting| "#{name}: #{greeting}!" }.join("\n")
end
{{greetings alice=hello bob=hi}}
<!-- The above would be rendered as: -->
alice: hello!
bob: hi!

Note that since keyword arguments in Ruby are represented as Symbol objects, which are not garbage collected in Ruby versions less than 2.2, accepting arbitrary attributes represents a security vulnerability if your application allows untrusted Curly templates to be rendered. Only use this feature with trusted templates if you're not on Ruby 2.2 yet.

Conditional blocks

If there is some content you only want rendered under specific circumstances, you can use conditional blocks. The {{#admin?}}...{{/admin?}} syntax will only render the content of the block if the admin? method on the presenter returns true, while the {{^admin?}}...{{/admin?}} syntax will only render the content if it returns false.

Both forms can have an identifier: {{#locale.en?}}...{{/locale.en?}} will only render the block if the locale? method on the presenter returns true given the argument "en". Here's how to implement that method in the presenter:

class SomePresenter < Curly::Presenter
  # Allows rendering content only if the locale matches a specified identifier.
  def locale?(identifier)
    current_locale == identifier
  end
end

Furthermore, attributes can be set on the block. These only need to be specified when opening the block, not when closing it:

{{#square? width=3 height=3}}
  <p>It's square!</p>
{{/square?}}

Attributes work the same way as they do for normal components.

Collection blocks

Sometimes you want to render one or more items within the current template, and splitting out a separate template and rendering that in the presenter is too much overhead. You can instead define the template that should be used to render the items inline in the current template using the collection block syntax.

Collection blocks are opened using an asterisk:

{{*comments}}
  <li>{{body}} ({{author_name}})</li>
{{/comments}}

The presenter will need to expose the method #comments, which should return a collection of objects:

class Posts::ShowPresenter < Curly::Presenter
  presents :post

  def comments
    @post.comments
  end
end

The template within the collection block will be used to render each item, and it will be backed by a presenter named after the component – in this case, comments. The name will be singularized and Curly will try to find the presenter class in the following order:

  • Posts::ShowPresenter::CommentPresenter
  • Posts::CommentPresenter
  • CommentPresenter

This allows you some flexibility with regards to how you want to organize these nested templates and presenters.

Note that the nested template will only have access to the methods on the nested presenter, but all variables passed to the "parent" presenter will be forwarded to the nested presenter. In addition, the current item in the collection will be passed, as well as that item's index in the collection:

class Posts::CommentPresenter < Curly::Presenter
  presents :post, :comment, :comment_counter

  def number
    # `comment_counter` is automatically set to the item's index in the collection,
    # starting with 1.
    @comment_counter
  end

  def body
    @comment.body
  end

  def author_name
    @comment.author.name
  end
end

Collection blocks are an alternative to splitting out a separate template and rendering that from the presenter – which solution is best depends on your use case.

Context blocks

While collection blocks allow you to define the template that should be used to render items in a collection right within the parent template, context blocks allow you to define the template for an arbitrary context. This is very powerful, and can be used to define widget-style components and helpers, and provide an easy way to work with structured data. Let's say you have a comment form on your page, and you'd rather keep the template inline. A simple template could look like:

<!-- post.html.curly -->
<h1>{{title}}</h1>
{{body}}

{{@comment_form}}
  <b>Name: </b> {{name_field}}<br>
  <b>E-mail: </b> {{email_field}}<br>
  {{comment_field}}

  {{submit_button}}
{{/comment_form}}

Note that an @ character is used to denote a context block. Like with collection blocks, a separate presenter class is used within the block, and a simple convention is used to find it. The name of the context component (in this case, comment_form) will be camel cased, and the current presenter's namespace will be searched:

class PostPresenter < Curly::Presenter
  presents :post
  def title; @post.title; end
  def body; markdown(@post.body); end

  # A context block method *must* take a block argument. The return value
  # of the method will be used when rendering. Calling the block argument will
  # render the nested template. If you pass a value when calling the block
  # argument it will be passed to the presenter.
  def comment_form(&block)
    form_for(Comment.new, &block)
  end

  # The presenter name is automatically deduced.
  class CommentFormPresenter < Curly::Presenter
    # The value passed to the block argument will be passed in a parameter named
    # after the component.
    presents :comment_form

    # Any parameters passed to the parent presenter will be forwarded to this
    # presenter as well.
    presents :post

    def name_field
      @comment_form.text_field :name
    end

    # ...
  end
end

Context blocks were designed to work well with Rails' helper methods such as form_for and content_tag, but you can also work directly with the block. For instance, if you want to directly control the value that is passed to the nested presenter, you can call the call method on the block yourself:

def author(&block)
  content_tag :div, class: "author" do
    # The return value of `call` will be the result of rendering the nested template
    # with the argument. You can post-process the string if you want.
    block.call(@post.author)
  end
end

Context shorthand syntax

If you find yourself opening a context block just in order to use a single component, e.g. {{@author}}{{name}}{{/author}}, you can use the shorthand syntax instead: {{author:name}}. This works for all component types, e.g.

{{#author:admin?}}
  <p>The author is an admin!</p>
{{/author:admin?}}

The syntax works for nested contexts as well, e.g. {{comment:author:name}}. Any identifier and attributes are passed to the target component, which in this example would be {{name}}.

Setting up state

Although most code in Curly presenters should be free of side effects, sometimes side effects are required. One common example is defining content for a content_for block.

If a Curly presenter class defines a setup! method, it will be called before the view is rendered:

class PostPresenter < Curly::Presenter
  presents :post

  def setup!
    content_for :title, post.title

    content_for :sidebar do
      render 'post_sidebar', post: post
    end
  end
end

Escaping Curly syntax

In order to have {{ appear verbatim in the rendered HTML, use the triple Curly escape syntax:

This is {{{escaped}}.

You don't need to escape the closing }}.

Comments

If you want to add comments to your Curly templates that are not visible in the rendered HTML, use the following syntax:

{{! This is some interesting stuff }}

Presenters

Presenters are classes that inherit from Curly::Presenter – they're usually placed in app/presenters/, but you can put them anywhere you'd like. The name of the presenter classes match the virtual path of the view they're part of, so if your controller is rendering posts/show, the Posts::ShowPresenter class will be used. Note that Curly is only used to render a view if a template can be found – in this case, at app/views/posts/show.html.curly.

Presenters can declare a list of accepted variables using the presents method:

class Posts::ShowPresenter < Curly::Presenter
  presents :post
end

A variable can have a default value:

class Posts::ShowPresenter < Curly::Presenter
  presents :post
  presents :comment, default: nil
end

Any public method defined on the presenter is made available to the template as a component:

class Posts::ShowPresenter < Curly::Presenter
  presents :post

  def title
    @post.title
  end

  def author_link
    # You can call any Rails helper from within a presenter instance:
    link_to author.name, profile_path(author), rel: "author"
  end

  private

  # Private methods are not available to the template, so they're safe to
  # use.
  def author
    @post.author
  end
end

Presenter methods can even take an argument. Say your Curly template has the content {{t.welcome_message}}, where welcome_message is an I18n key. The following presenter method would make the lookup work:

def t(key)
  translate(key)
end

That way, simple ``functions'' can be added to the Curly language. Make sure these do not have any side effects, though, as an important part of Curly is the idempotence of the templates.

Layouts and content blocks

Both layouts and content blocks (see content_for) use yield to signal that content can be inserted. Curly works just like ERB, so calling yield with no arguments will make the view usable as a layout, while passing a Symbol will make it try to read a content block with the given name:

# Given you have the following Curly template in
# app/views/layouts/application.html.curly
#
#   <html>
#     <head>
#       <title>{{title}}</title>
#     </head>
#     <body>
#       <div id="sidebar">{{sidebar}}</div>
#       {{body}}
#     </body>
#   </html>
#
class ApplicationLayout < Curly::Presenter
  def title
    "You can use methods just like in any other presenter!"
  end

  def sidebar
    # A view can call `content_for(:sidebar) { "some HTML here" }`
    yield :sidebar
  end

  def body
    # The view will be rendered and inserted here:
    yield
  end
end

Rails helper methods

In order to make a Rails helper method available as a component in your template, use the exposes_helper method:

class Layouts::ApplicationPresenter < Curly::Presenter
  # The components {{sign_in_path}} and {{root_path}} are made available.
  exposes_helper :sign_in_path, :root_path
end

Testing

Presenters can be tested directly, but sometimes it makes sense to integrate with Rails on some levels. Currently, only RSpec is directly supported, but you can easily instantiate a presenter:

SomePresenter.new(context, assigns)

context is a view context, i.e. an object that responds to render, has all the helper methods you expect, etc. You can pass in a test double and see what you need to stub out. assigns is the hash containing the controller and local assigns. You need to pass in a key for each argument the presenter expects.

Testing with RSpec

In order to test presenters with RSpec, make sure you have rspec-rails in your Gemfile. Given the following presenter:

# app/presenters/posts/show_presenter.rb
class Posts::ShowPresenter < Curly::Presenter
  presents :post

  def body
    Markdown.render(@post.body)
  end
end

You can test the presenter methods like this:

# You can put this in your `spec_helper.rb`.
require 'curly/rspec'

# spec/presenters/posts/show_presenter_spec.rb
describe Posts::ShowPresenter, type: :presenter do
  describe "#body" do
    it "renders the post's body as Markdown" do
      assign(:post, double(:post, body: "**hello!**"))
      expect(presenter.body).to eq "<strong>hello!</strong>"
    end
  end
end

Note that your spec must be tagged with type: :presenter.

Examples

Here is a simple Curly template – it will be looked up by Rails automatically.

<!-- app/views/posts/show.html.curly -->
<h1>{{title}}<h1>
<p class="author">{{author}}</p>
<p>{{description}}</p>

{{comment_form}}

<div class="comments">
  {{comments}}
</div>

When rendering the template, a presenter is automatically instantiated with the variables assigned in the controller or the render call. The presenter declares the variables it expects with presents, which takes a list of variables names.

# app/presenters/posts/show_presenter.rb
class Posts::ShowPresenter < Curly::Presenter
  presents :post

  def title
    @post.title
  end

  def author
    link_to(@post.author.name, @post.author, rel: "author")
  end

  def description
    Markdown.new(@post.description).to_html.html_safe
  end

  def comments
    render 'comment', collection: @post.comments
  end

  def comment_form
    if @post.comments_allowed?
      render 'comment_form', post: @post
    else
      content_tag(:p, "Comments are disabled for this post")
    end
  end
end

Caching

Caching is handled at two levels in Curly – statically and dynamically. Static caching concerns changes to your code and templates introduced by deploys. If you do not wish to clear your entire cache every time you deploy, you need a way to indicate that some view, helper, or other piece of logic has changed.

Dynamic caching concerns changes that happen on the fly, usually made by your users in the running system. You wish to cache a view or a partial and have it expire whenever some data is updated – usually whenever a specific record is changed.

Dynamic Caching

Because of the way logic is contained in presenters, caching entire views or partials by the data they present becomes exceedingly straightforward. Simply define a #cache_key method that returns a non-nil object, and the return value will be used to cache the template.

Whereas in ERB you would include the cache call in the template itself:

<% cache([@post, signed_in?]) do %>
  ...
<% end %>

In Curly you would instead declare it in the presenter:

class Posts::ShowPresenter < Curly::Presenter
  presents :post

  def cache_key
    [@post, signed_in?]
  end
end

Likewise, you can add a #cache_duration method if you wish to automatically expire the fragment cache:

class Posts::ShowPresenter < Curly::Presenter
  ...

  def cache_duration
    30.minutes
  end
end

In order to set any cache option, define a #cache_options method that returns a Hash of options:

class Posts::ShowPresenter < Curly::Presenter
  ...

  def cache_options
    { compress: true, namespace: "my-app" }
  end
end

Static Caching

Static caching will only be enabled for presenters that define a non-nil #cache_key method (see Dynamic Caching.)

In order to make a deploy expire the cache for a specific view, set the version of the view to something new, usually by incrementing by one:

class Posts::ShowPresenter < Curly::Presenter
  version 3

  def cache_key
    # Some objects
  end
end

This will change the cache keys for all instances of that view, effectively expiring the old cache entries.

This works well for views, or for partials that are rendered in views that themselves are not cached. If the partial is nested within a view that is cached, however, the outer cache will not be expired. The solution is to register that the inner partial is a dependency of the outer one such that Curly can automatically deduce that the outer partial cache should be expired:

class Posts::ShowPresenter < Curly::Presenter
  version 3
  depends_on 'posts/comment'

  def cache_key
    # Some objects
  end
end

class Posts::CommentPresenter < Curly::Presenter
  version 4

  def cache_key
    # Some objects
  end
end

Now, if the version of Posts::CommentPresenter is bumped, the cache keys for both presenters would change. You can register any number of view paths with depends_on.

Curly integrates well with the caching mechanism in Rails 4 (or Cache Digests in Rails 3), so the dependencies defined with depends_on will be tracked by Rails. This will allow you to deploy changes to your templates and have the relevant caches automatically expire.

Thanks

Thanks to Zendesk for sponsoring the work on Curly.

Contributors

Build Status


Author: zendesk
Source code: https://github.com/zendesk/curly

#ruby   #ruby-on-rails 

Microsoft Excel Tutorial - Objects In Ms Excel- Excel Worksheet Objects

In this MS Excel tutorials, video we are going to see the differnce between tables and cell ranges in MS Excel. Also we are going to see that how can we create a Table from data given to us and what all changes we can apply to our tables.

Welcome to the The Beginner’s Guide course to Excel. This course enables you to Learn MS Excel in simple and easy steps. In this Microsoft Excel Basics Tutorial series we will start from the basics and gradually move towards the Expert level in Microsoft Excel. This MS Excel course provides the Beginners to Intermediate Excel Skills, Tips, and Tricks. In this course we will learn how to Enter and edit Excel data, Format numbers, fonts and alignment, Make simple pivot tables and charts, Create simple Excel formulas, How to Use Excel Functions IF and VLOOKUP. Learn common Excel functions used in any Office, How to Create dynamic reports, Build Excel formulas to analyze date, text fields, values and arrays and much more advanced stuff.

In this video we will see the Overview of formulas in Excel. We will see Basic Excel formulas & functions with examples .

#microsoft excel #excel #ms excel