W

로컬 텍스트 엑셀 파일 읽기/쓰기

· 2010-01-23 (토) 20:44:45 · 6943

익스플로우의 보안에 허용만 가능하면 자바스크립트 상에서도 읽기/쓰기가 가능하다.

 

우선 text파일 읽고 쓰는 예제이다.(C:\\book1.txt를 읽고 씀)

 

=====================================================================================================================

<html>
<head>
<title>file save/load</title>

 

<script type="text/javascript">

    var fso=new ActiveXObject("Scripting.FileSystemObject");
    var filename="C:\\book1.txt";
    function savefile() {
        if (!fso.FileExists(filename)) {
            fso.CreateTextFile(filename,true);
        }
        var f=fso.OpenTextFile(filename,2,true);
        f.Write(myarea.innerHTML);
        f.Close();
    }
   
    function loadfile() {
        if (!fso.FileExists(filename)) {
            fso.CreateTextFile(filename,true);
        }
        var f=fso.OpenTextFile(filename,1);
        r=f.ReadAll();
        f.Close();
        myarea.innerHTML=r;
    }
   
   
    //function window.onload() {
    //    loadfile(filename);
    //}
</script>


</head>
<body>
 <table>
  <tr>
   <td>
    <div id=myarea contenteditable=true style="width:320;height:240;border:solid 2 inset;overflow:scroll;background-color:silver;"></div>
    <br><input type=button value=load onclick=loadfile()><input type=button value=save onclick=savefile()>
   </td>
  </tr>
 </table>
</form>
</body>
</html>

 

======================================Excel 파일 열고 쓰기 =================================================

- 쓰기 -

<script type="text/javascript">

// Declare the variables
var Excel, Book;

// Create the Excel application object.
Excel = new ActiveXObject("Excel.Application");

// Make Excel visible.
Excel.Visible = true;

// Create a new work book.
Book = Excel.Workbooks.Add()

// Place some text in the first cell of the sheet.
Book.ActiveSheet.Cells(1,1).Value = "This is column A, row 1";

// Save the sheet.
Book.SaveAs("C:\\book1.xls");

// Close Excel with the Quit method on the Application object.
Excel.Application.Quit();
</script>

 

- 열기 -

function StartExcel() {
var oExcel;

var oWBook;
oExcel = new ActiveXObject("Excel.Application");

oExcel.Visible = true;

oExcel.workbooks.open("C:/test.xls");

oExcel.Quit();

oExcel = null;
}

 

간단한 파일 읽기의 경우 상당히 유용할 수 있겠다..

 
[이 게시물은 관리자님에 의해 2011-10-31 17:16:08 PHP & HTML에서 이동 됨]
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

8,187건
+
제목 글쓴이 날짜 조회
10-11-17 조회 2,333
10-11-16 조회 2,636
10-11-16 조회 2,139
10-11-16 조회 2,375
10-11-15 조회 2,848
10-11-15 조회 2,361
10-11-15 조회 3,102
10-11-15 조회 2,123
10-11-15 조회 2,231
10-11-15 조회 2,783
10-11-15 조회 2,486
10-11-14 조회 2,140
10-11-14 조회 4,351
10-11-14 조회 2,681
10-11-14 조회 3,692
10-11-13 조회 3,517
10-11-13 조회 2,496
10-11-13 조회 3,715
10-11-12 조회 2,322
10-11-12 조회 2,705
10-11-11 조회 3,876
10-11-11 조회 2,099
10-11-11 조회 2,714
10-11-10 조회 2,940
10-11-10 조회 2,206
10-11-10 조회 2,561
10-11-10 조회 2,044
10-11-09 조회 3,380
10-11-09 조회 2,894
10-11-09 조회 2,226
10-11-09 조회 1,925
10-11-09 조회 1,993
10-11-09 조회 2,537
10-11-09 조회 2,497
10-11-08 조회 1,908
10-11-08 조회 1,793
10-11-08 조회 2,080
10-11-08 조회 2,083
10-11-08 조회 3,006
10-11-08 조회 1,927
10-11-08 조회 2,070
10-11-08 조회 2,031
10-11-08 조회 2,289
10-11-08 조회 3,055
10-11-07 조회 2,946
10-11-07 조회 1.6만
10-11-07 조회 4,525
10-11-06 조회 2,082
10-11-06 조회 2,089
10-11-06 조회 2,242
10-11-06 조회 2,018
10-11-06 조회 1,981
10-11-06 조회 1.3만
10-11-05 조회 2,571
10-11-05 조회 2,543
10-11-05 조회 2,678
10-11-04 조회 2,585
10-11-04 조회 1,933
10-11-04 조회 2,792
10-11-04 조회 2,319
10-11-04 조회 1,961
10-11-04 조회 2,138
10-11-04 조회 2,200
10-11-04 조회 2,776
10-11-04 조회 2,129
10-11-04 조회 2,105
10-11-04 조회 2,333
10-11-03 조회 2,106
10-11-03 조회 2,970
10-11-03 조회 2,689
10-11-03 조회 4,266
10-11-03 조회 2,968
10-11-03 조회 1,995
10-11-03 조회 1,945
10-11-02 조회 2,171
10-11-02 조회 2,783
10-11-02 조회 2,807
10-11-01 조회 2,010
10-11-01 조회 2,101
10-11-01 조회 2,389
10-11-01 조회 2,597
10-10-31 조회 2,366
10-10-31 조회 2,318
10-10-31 조회 2,585
10-10-30 조회 1,995
10-10-30 조회 1,972
10-10-30 조회 2,491
10-10-30 조회 1,992
10-10-29 조회 3,160
10-10-29 조회 3,742
10-10-29 조회 2,178
10-10-29 조회 2,258
10-10-29 조회 3,130
10-10-28 조회 2,355
10-10-28 조회 2,453
10-10-28 조회 2,850
10-10-28 조회 3,011
10-10-28 조회 3,270
10-10-27 조회 2,570
10-10-27 조회 3,318