Você está na página 1de 32

2/29/16

Optativa 4to (IIN400)

Importando Datos a Excel

Carlos A. Suárez-Núñez
csuarez@usfq.edu.ec

Slides adaptados de: ISE 3024 – Virginia Tech - Prof. John P. Shewchuk

Copyright ©2013 Pearson Educa9on, Inc. publishing as Pren9ce Hall.

1-0

6. IMPORTING DATA INTO EXCEL


q  You’venow seen how to work with Excel lists, work with
multiple worksheets and workbooks simultaneously, and
design user-friendly applications.

q  Each of these: user entered data directly.

q  Manycases: data may already be available in computer-


compatible format – simply need to import it.

q  This
chapter: how to import text, database, and web
page data into Excel.
6–1

1
2/29/16

6.1 Problem Scenario: Planned Lead Times at LJ


Machining

q  LJMachining performs a variety of manufacturing


services, including machining, fabrication, and
assembly work.

q  Two of their current products – pulleys and mounting


plates – are produced on a regular basis, using time-
phased production.

6–2

Pulley (product no. 2214-002):


•  single-level BOM item
•  machined from 713 aluminum

Mounting Plate: assembly.


Indented BOM:
•  2214-003 Mounting Plate
• 2214-004 Base Plate (1)
•  2214-005 Forward Fix Plate (1)
•  2214-006 Aft Fix Plate (1)

q  These products might look familiar to you


6–3

2
2/29/16

q  MRP (Material Requirements Planning) used to plan


production of these items. MRP requires
• lot sizes
•  planned lead times (PLTs) for each item.

q  Calculation
of PLTs:
where K = slack time factor
LS = lot size

6–4

Example: What is the PLT for a lot of 100 mounting plates


(2214-003, p. 7), given that a slack time factor of 3 is used?

PLT = K*(total setup time + LS * per-item run time)

6–5

3
2/29/16

q  An Excel application (LJPlanning.xlsm) has already


been developed for calculating PLTs.
•  process plans already completed for 2214-003
(Mounting Plate) and 2214-005 (Forward Fix Plate).
•  worksheets already started for remaining items (Pulley,
Base Plate, Aft Fix Plate), but process planning data is
missing.

q  The missing data is available as follows:


•  Pulley: two text files (PULLEY1.txt and PULLEY2.txt).
•  Base Plate: Access database (LJData.accdb).
•  Aft Fix Plate: Web page (RyersonIndustries.htm)
6–6

6–7

4
2/29/16

6–8

Public Sub PLT() ActiveCell.FormulaR1C1 = ""


Dim PLT As Single N = Nsheets + 2
Dim Run As Single Else: N = N + 1
Nsheets = Application.Sheets.Count End If
Product = Range("D7").Value Wend
LS = Range("D9").Value End Sub
K = Range("D11").Value
N = 2
While N <= Nsheets
If Sheets(N).Name = Product Then Sub ClearValues()
Sheets(N).Select ActiveSheet.Unprotect
Setup = Range("E19").Value Run Range("D7").Select
= LS * Range("F19").Value N = ActiveCell.FormulaR1C1 = ""
Nsheets + 1 Sheets(1).Select Range("D9").Select
ActiveSheet.Unprotect ActiveCell.FormulaR1C1 = ""
Range("D11").Select
PLT = K * (Setup + Run) ActiveCell.FormulaR1C1 = ""
Range("F15").Value = Setup Range("F15").Select
Range("F16").Value = Run ActiveCell.FormulaR1C1 = ""
Range("F18").Value = PLT Range("F16").Select
PLT = PLT / 60# ActiveCell.FormulaR1C1 = ""
Range("I18").Value = PLT
Range("F18").Select
ActiveSheet.Protect _
ActiveCell.FormulaR1C1 = ""
DrawingObjects:=True, _
Range("I18").Select
Contents:=True, _
ActiveCell.FormulaR1C1 = ""
Scenarios:=True
Range("D7").Select
ActiveSheet.Protect DrawingObjects:=_
ElseIf N = Nsheets Then
MsgBox "Product not found",_ True, Contents:=True,_
vbCritical,"Invalid Product" Scenarios:=True
Sheets(1).Select End Sub
Range("D7").Select

6–9

5
2/29/16

q  LJ Machining thus needs to perform the following:


1. Import Text Data (Pulley)
2. Import Database Data (Base Plate)
3. Import Web-based Data (Aft Fix Plate)
4. Refresh Imported Data
5. Work with Existing Data Import Procedures
q  Let’s see how these activities can be accomplished.
q  All of the files involved can be downloaded from Scholar:
F D2L:
Syllabus y Contenidos ð Ejercicios en Clase
Capítulo 6 – Importando Datos a Excel

6 – 10

6.2 Importing Data into Excel at LJ Machining

1. Import Text Data (for Pulley)

q  Text file (.txt) = data file with text, numbers only.

q  One of easiest ways to store/retrieve data:


•  data only: no messing around with formats, etc.
•  most software applications (including Excel) can both
read and write text files.
•  smaller files.
6 – 11

6
2/29/16

q  How can we get text data into table (list) form?

•  columns: use delimiters or fixed-width data.


delimiter = symbol (e.g., tab) used to separate successive
data entries in the same row.
Most common delimiters: tab, space,
comma (see next page).

•  rows: use return to signify end of a row.

6 – 12

Tab-delimited data: Item On-Hand ROP ROQ Ordered?


A47 240 50 200 N
B19 48 10 30 N
D57 368 100 200 N

Space-delimited data: Item On-Hand ROP ROQ Ordered?


A47 240 50 200 N
B19 48 10 30 N
D57 368 100 200 N

Comma-delimited data: Item,On-Hand,ROP,ROQ,Ordered?


A47,240,50,200,N
B19,48,10,30,N
D57,368,100,200,N
Fixed width data:
Item On-hand ROP ROQ Ordered?
A47 240 50 200 N
B19 48 10 30 N
D57 368 100 200 N
6 – 13

7
2/29/16

q  Basic procedure for importing text file data into Excel:

•  Specify file type and parameter


-  file type: delimited or fixed width.
-  parameter: delimiter or column widths.

•  Select row to start import at


-  cannot skip or reorder rows.

•  Select columns of the file to import


-  skip those not desired: cannot reorder columns.

•  Specify location for the imported data


6 – 14

q  Pulley text files for LJ Machining:


10 Cast pulley C
20 Chuck boss; rough & finish face hub, rough & finish turn hub dia. T
30 Machine groove T
40 Center drill, drill, ream center hole T
50 Remove, insert mandrel, reverse. Face boss, rough & finish turn boss dia.
P, T
60 Deburr machined surfaces, remove mandrel P,T
70 Broach keyway P

PULLEY1.txt (tab-delimited)

Setup Run
Op Machine (min.) (min.)
10 FURN-01 30 45
20 L-04 or L-06 5 20
30 L-04 or L-06 5 5
40 L-04 or L-06 2 10
50 L-04 or L-06 10 20
60 L-04 or L-06 2 5
70 P-14 2 2

PULLEY2.txt (fixed-width data)


6 – 15

8
2/29/16

q  Import as follows:

•  PULLEY1.txt: specify tab-delimited, start importing


at row 1, import to starting cell location A4.

•  PULLEY2.txt: specify fixed-width data and set


column widths, start at row 3, skip 1st column (Op. #),
import to starting cell location D4.

6 – 16

q  Result:

6 – 17

9
2/29/16

2. Import Database Data (for Base Plate)

q  Database = set of tables.


•  each column = particular type of information (field).
•  each row = record.

q  Common fields used to link tables together, e.g.,


Customer Order
customerName state orderNo customerName itemNo
John Smith VA 4104 Tim Richards 5779A
Alice Jones WV 2336 Julie Barnes 12GB-05
Tim Richards PA 2875 Tim Richards 7084A-12
Julie Barnes VA
common field
6 – 18

q  Unlike
text files, databases are very flexible when it
comes to retrieving data.

q  Can

•  select any columns (as long as tables involved linked via


a common field),
•  select any rows, and
•  arrange the column and row orders any way we like.

6 – 19

10
2/29/16

q  Basic procedure for importing database data into Excel:

•  Specify columns to import


-  can be from multiple tables, as long as all tables have
a common field (e.g., customerName).
-  be sure to include this column.

•  Arrange columns in desired sequence

•  Specify rows to import, based upon some criteria

•  Specify row ordering, based upon some criteria

•  Specify the location for the imported data


6 – 20

q  The Access database (LJData.accdb) that LJ Machining is


to use has two relevant tables:
Operation
planNo opNo description machine setup run
PP-301 10 Cut to length VBS-001 5 5
PP-301 20 Punch mounting holes PP-01 15 1
PP-301 30 Deburr side holes DP-03 10 2
PP-301 40 Side mill longitudinal slot (0.25-in. width) HM-04 30 15
PP-301 50 End mill transverse slot (0.50-in.width) VM-02 15 1
PP-301 60 Deburr slots (none) 2 5
PP-301 70 Mark S/N on bottom face (none) 0 1
PP-301 80 Inspect to drwg. (none) 5 10
PP-303 10 Cut to length VBS-001 5 5
PP-303 20 Cut radial slot, mounting holes, and “X” MC-H 15 8
. . . . . .
. . . . . .
. . . . . .

6 – 21

11
2/29/16

Machine
machine dept description quantity
CMM I Helmel coordinate measuring machine 1
DP-03 D Orbit drill press 3
HM-04 M Cincinnatti 2mh horizontal milling machine 2
HM-06 M Van Norman 26SU horizontal milling machine 1
HOB W Hobart arc welder 6
MC-H M Hurco 5-axis machining center 1
P50 W GE P50 articulated robot welding center 1
PP-01 P Scotchman F160/130 punch press 1
ROCKB I Rockwell B hardness tester 1
VBS-001 S Marvel Mark II vertical band saw 1
VM-02 M Bridgeport vertical milling machine 2
VM-03 M Cincinnatti Toolmaster vertical milling machine 1

6 – 22

q  TheBase Plate (2214-004) data would be imported


from this database as follows:
•  select all columns from the Operation table, and then
department from the Machine table.
•  arrange the columns in the order needed, i.e., opNo,
description, dept, machine, setup, run, planNo.
•  import rows based upon ?

•  order rows based upon ?

•  import to starting cell location A4.


6 – 23

12
2/29/16

q  Result:

6 – 24

3. Import Web-based Data (for Aft Fix Plate)

q  Web page = collection of data, arranged and formatted


using specific language designed for World Wide Web.
•  HTML

q  Table structures: very commonly used in web pages.

q  Result: web pages well-suited for data import into Excel.

6 – 25

13
2/29/16

q  Basic procedure for importing web page data into Excel:

•  Locate the web page of interest (browser, within Excel)

•  Select the table(s) of interest from the web page

•  Specify options
- e.g., formatting

•  Specify the location for the imported data

6 – 26

q  Theweb page that LJ Machining is to use belongs to


another company.

•  LJ Machining manufactures the Aft Fix Plate through a


subcontractor, Ryerson Industries.

•  Ryerson uses Web pages used for all product and


process planning data.

•  LJ Machining given access to Ryerson web site


containing process planning data.

6 – 27

14
2/29/16

6 – 28

q  Note problem here:


•  Ryerson table:
Op. Description Machine Setup Run

•  Our table:
Op. Description Dept. Machine Setup Run

q  Web page: can’t select columns of interest, must take


entire table.

q  Also,can’t just import entire table, then move columns


afterwards (why)?

6 – 29

15
2/29/16

q  One approach:
•  locate RyersonIndustries.htm (browser).

•  select the Process Plan table


•  import to just below Excel table, e.g., start at A21.
•  formulas in Excel table to refer to imported table.

6 – 30

6 – 31

16
2/29/16

4. Refresh Imported Data

q  Importing data (text, database or web page) into Excel


doesn’t just copy the data. Rather, a connection is
maintained to the data source (external data).

q  Allows us to update, or refresh, the data.

q  Various alternatives:
•  manually.
•  automatically (every x minutes).
•  whenever the Excel file is opened.

q  When might LJ Machining wish to use each of these?


6 – 32

5. Work with Existing Data Import Procedures

q  Whenever you setup a procedure to import data, Excel


saves the steps as a query.
q  You can then recall the query at a later date to
•  recall how it works.
•  change something.

q  Additionally, you can reuse the query to import that data,


in the exact same way, to a different location in the
workbook.
q  When might LJ Machining need to reuse one of the data
import procedures developed?
6 – 33

17
2/29/16

6.3 Self-Study Computer Assignment

1.  Go through this chapter on your own, to perform the


various data import tasks using
LJPLanning.xlsm, PULLEY1.txt, PULLEY2.txt,
LJData.accdb, and RyersonIndustries.htm.
•  download these files from D3L

6 – 34

6.4 Detailed Procedures for Importing Data into Excel

q  This section shows how we can import data into Excel 2010.
•  detailed steps for using the software.

q  We’ll
demonstrate with our LJ Machining problem scenario,
where required.

6 – 35

18
2/29/16

6.4.1 Importing Data from a Text File

1.  On the Data tab, click on From Text. The Import Text File
dialog box will appear.

2.  Locate and select the desired text file, then click on
Import. The Text Import Wizard will then launch, with the
first screen as shown on the following page.

3.  First screen (Step 1 of 3), select


•  whether the file is delimited or fixed width.
•  what row to start importing data at.
Then click Next>.
6 – 36

6 – 37

19
2/29/16

4.  Second screen (Step 2 of 3):


•  if Delimited was selected in
Step 1, select the delimiter to
use.
•  if Fixed width was selected in
Step 1, establish the column
breaks.

Click Next>.
6 – 38

5.  Third screen (Step 3 of 3), specify


the data format for each column.
Alternatively, you can select to skip
each column when importing data.
Once done, click Finish.

6.  The Import Data dialog box


opens. Enter the starting
location for the data as shown at
right, then click Properties....

7.  On the External Data Range Properties dialog box,


uncheck Adjust column width. Click OK to close this
dialog box, then click OK again to close the Import Data
dialog box.
6 – 39

20
2/29/16

q  Example: Importing Pulley data (LJ Machining)

PULLEY1.txt:
3. First screen: select Delimited, start with row 1.

4.  Second screen: select tab delimiter.


5.  Third screen: change format of the 2nd column
(Description) to Text.
6.  Import Data box: existing worksheet, cell $A$4.
6 – 40

PULLEY2.txt:
3.  First screen: select Fixed width, start with row 3.

4.  Second screen: set column breaks as shown on p. 38.

5.  Third screen: we already have the operation #s’s from


the first file we imported, so check Do not import
column (skip) for the 1st column. Then change
format of the 2nd column to Text.

6.  Import Data box: existing worksheet, cell $D$4.

6 – 41

21
2/29/16

6 – 42

6.4.2 Importing Data from a Database

1.  On the Data tab, click on From Other Sources. Then


select From Microsoft Query.

2.  The Choose Data Source dialog box will appear. In the
Database tab, click on MS Access Database*, then click
OK.

3.  The Select Database dialog box will then appear.


Locate the database of interest, then click OK. The
Query Wizard will then launch, with the first screen as
shown on the following page.

6 – 43

22
2/29/16

4.  First screen (Choose Columns): select and order the


columns of the database tables to import.
•  left window: select the columns to import.
- All columns in a table: select the table name, then
click >.
6 – 44

- Particular column in table: click on the + in front of


the table name to display the columns, then select
an individual column and click >.

•  right window: establish column order. Use the scroll


buttons on the right to reorder as necessary.

•  bottom window: data preview. Select a column, then


click the Preview Now button.

5.  Second screen (Filter Data): select the rows of the


database tables to import.
•  select the desired column in the Column to filter list.
6 – 45

23
2/29/16

•  specify the filtering criteria based upon that column:


-  select an operator (equals, does not equal, etc.)
from the first drop-down menu.
-  select one of the possible values from the second
drop-down menu.
•  repeat the above as desired for multi-level filtering.

6.  Third screen (Sort Order): specify the order in which the
imported rows are to appear.
•  select the column to sort by in the Sort by drop-
down list.
•  Select Ascending or Descending (radio buttons).
•  Repeat the above as desired for multi-level sorts.
6 – 46

7.  Fourth screen (Finish): specify where to put the data.


•  ensure the Return Data to Microsoft Office Excel
button is selected (we simply want to import the
data), then click Finish.

8.  The Import Data dialog box opens. Ensure Table and
Existing Worksheet are selected, then enter the starting
location for the data and click OK.

6 – 47

24
2/29/16

q  Example: Importing Base Plate data (LJ Machining)

3.  Select Database dialog box: LJData.accdb.

4.  Choose Columns screen:


•  select Operation, click >.
•  click on + in front of Machine, then select
dept and click >.
•  establish column order as shown below.

6 – 48

5. Filter Data screen:

6. Sort Order screen:

6 – 49

25
2/29/16

8. Starting location = $A$4.

6 – 50

6.4.3 Importing Data from a Web Page

1.  On the Data tab, click on From Web. The New Web
Query dialog box appears, with your default Web
browser running.

2.  Type the web page address (URL, Uniform Resource


Locator) in the Address box, then click on Go to load the
web page.

3.  You will see yellow arrow boxes ( ) indicating tables that
can be imported. Click on the arrow box corresponding to
the table you want to import.The arrow box changes to a
checkbox ( ).

6 – 51

26
2/29/16

4.  Click on Options... to open the Web Query Options


window. Of particular concern are the Formatting options:
•  None ⇒ import only the data.
•  Rich text formatting ⇒ text w/formatting.
•  Full HTML formatting ⇒ text, HTML tags, and
hyperlinks.
Select the desired option, then click OK.

5.  The Import Data dialog box opens. Enter the starting
location for the data, then click Properties....

6.  On the External Data Range Properties dialog box,


uncheck Adjust column width. Click OK to close, then
click OK again to close the Import Data dialog box.
6 – 52

q  Example: Importing Aft Fix Plate data (LJ Machining)


2.  The Ryerson Industries web page will be located on
your computer (once downloaded from Scholar).
Open it directly by typing
file:///C:/[path]/RyersonIndustries.html
in the Address box and clicking Go.

3.  Select the table as shown on the following page.

6 – 53

27
2/29/16

6 – 54

4.  Web Query Options screen:


select None for Formatting.

5.  Import Data dialog box:


existing worksheet, cell
$A$21.

6 – 55

28
2/29/16

•  Note the following here:

-  The imported header is not needed and can be


deleted. BUT make sure the Setup and Run
totals are still in row 19!

-  The Ryerson Industries table did not specify a


department for each operation, so the last three
columns of imported data must be shifted
accordingly.

6 – 56

6.4.4 Refreshing Imported Data in Excel

q  To manually refresh a particular range of imported data on


a worksheet:
1.  Select the worksheet, then click anywhere within
the imported data range.
2.  Either (i) right-click, then select refresh, or (ii) select
the Data tab, then select Refresh from the Refresh All
drop-down menu.

q  To manually refresh ALL the imported


data in a workbook:
1.  On the Data tab, select Refresh All
from the drop-down menu).
6 – 57

29
2/29/16

q  To set up automatic data refresh:


1.  On the Data tab, click on Connections. The
Workbook Connections dialog box appears,
showing all the
connections to
external data
(i.e., data
import links),
e.g.,

6 – 58

2.  Select on the connection of interest, then click on


Properties.... The Connections Properties dialog
box appears.
3.  Set the Refresh control option (below) as desired.

Text Files:

4. Click OK twice to close the dialog boxes.


6 – 59

30
2/29/16

6.4.5 Viewing/Editing Queries

1.  On the Data tab, click on Connections. The Workbook


Connections dialog box appears, showing all the
connections to external data (i.e., data import links), as
shown on p. 50.

2.  Select the connection of interest, then click on


Properties.... The Connections Properties dialog box
opens up.

3.  Click the Definition tab, then select Edit Query.... Excel
will take you through the steps used to create your query
once again. You can simply examine what was done, or
make changes as needed.
6 – 60

6.4.6 Reusing Queries

1.  On the Data tab, click on Existing Connections. The


Existing Connections dialog box appears.

2.  Select Connections in this


Workbook from the drop-
down menu. All of the
existing connections to
external data (i.e.,
data import links) are
shown, e.g.,

6 – 61

31
2/29/16

3.  Select the connection of interest, then click


Open. The Import Data dialog box will appear.

4.  Type in or interactively select the starting location


(worksheet, then upper left corner cell) for importing
the data, then click OK.

A new connection to the data source is made, and the


data is imported per the query.

(If you open the Existing Connections dialog box again,


you will see the new connections you just created).

6 – 62

32

Você também pode gostar