W

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

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

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

 

우선 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,188건
+
제목 글쓴이 날짜 조회
10-09-25 조회 2,726
10-09-19 조회 2,763
10-09-15 조회 2,761
10-09-15 조회 4,166
10-09-15 조회 3,388
10-09-15 조회 2,495
10-09-07 조회 3,608
10-08-27 조회 4,071
10-06-11 조회 4,246
10-05-31 조회 2,494
10-02-27 조회 5,007
10-02-09 조회 3,755
09-10-10 조회 7,346
09-03-19 조회 3,205
09-02-09 조회 3,469
09-02-09 조회 4,533
08-11-01 조회 2,914
08-09-29 조회 4,566
08-09-26 조회 3,515
08-09-26 조회 3,590
08-09-26 조회 2,727
08-09-26 조회 3,770
08-09-26 조회 3,498
08-09-26 조회 4,262
08-09-18 조회 3,585
08-09-09 조회 3,236
08-08-28 조회 2,775
08-07-06 조회 3,546
08-05-21 조회 4,710
08-05-13 조회 4,544
08-04-17 조회 4,923
08-02-19 조회 3,544
08-01-18 조회 3,845
08-01-10 조회 3,823
07-10-22 조회 3,656
07-10-09 조회 4,314
07-10-03 조회 3,516
07-07-06 조회 4,216
07-07-06 조회 4,428
07-07-06 조회 4,037
07-06-28 조회 3,574
07-06-05 조회 3,576
07-06-05 조회 4,122
07-05-30 조회 3,295
07-05-02 조회 3,688
07-04-15 조회 5,149
07-04-11 조회 3,631
07-04-05 조회 3,933
07-03-31 조회 3,150
07-03-31 조회 4,126
07-03-30 조회 3,737
07-03-24 조회 4,007
07-03-22 조회 3,659
07-03-12 조회 4,414
07-02-16 조회 3,276
07-02-14 조회 5,168
07-02-10 조회 3,999
07-02-09 조회 4,389
07-01-19 조회 4,049
07-01-16 조회 4,978
06-12-16 조회 5,842
06-11-30 조회 3,602
06-11-25 조회 3,710
06-10-15 조회 5,074
06-09-26 조회 5,310
06-09-26 조회 5,428
06-09-22 조회 4,277
06-09-21 조회 3,547
06-09-21 조회 3,643
06-09-02 조회 3,486
06-08-08 조회 5,118
06-07-20 조회 3,732
06-07-17 조회 3,361
06-07-13 조회 4,184
06-07-11 조회 3,486
06-07-11 조회 3,492
06-07-11 조회 3,847
06-06-29 조회 6,072
06-06-19 조회 6,465
06-06-02 조회 3,516
06-05-24 조회 5,001
06-05-14 조회 7,780
06-05-08 조회 3,902
06-02-02 조회 5,464
05-12-16 조회 4,516
05-12-05 조회 5,165
05-06-28 조회 4,121
05-04-11 조회 4,069
05-04-11 조회 4,255
05-04-11 조회 3,319
05-03-13 조회 3,222
05-03-12 조회 4,299
04-12-08 조회 7,781
04-12-01 조회 5,187
04-11-28 조회 3,369
04-11-28 조회 3,211
04-08-05 조회 5,623
04-08-05 조회 4,976
04-08-05 조회 5,584